diff --git a/presto-docs/src/main/sphinx/connector/iceberg.rst b/presto-docs/src/main/sphinx/connector/iceberg.rst index a8c3c7d362b06..86f83bb3674c6 100644 --- a/presto-docs/src/main/sphinx/connector/iceberg.rst +++ b/presto-docs/src/main/sphinx/connector/iceberg.rst @@ -1051,7 +1051,7 @@ that is stored using the ORC file format, partitioned by ``ds`` and partitioning = ARRAY['ds', 'country'] ) -Create an Iceberg table with Iceberg format version 2:: +Create an Iceberg table with Iceberg format version 2 and with commit_retries set to 5:: CREATE TABLE iceberg.web.page_views_v2 ( view_time timestamp, @@ -1063,7 +1063,8 @@ Create an Iceberg table with Iceberg format version 2:: WITH ( format = 'ORC', partitioning = ARRAY['ds', 'country'], - format_version = '2' + format_version = '2', + commit_retries = 5 ) Partition Column Transform @@ -1203,6 +1204,11 @@ The table is partitioned by the transformed value of the column:: ALTER TABLE iceberg.web.page_views ADD COLUMN ts timestamp WITH (partitioning = 'hour'); +Table properties can be modified for an Iceberg table using an ALTER TABLE SET PROPERTIES statement. Only `commit_retries` can be modified at present. +For example, to set `commit_retries` to 6 for the table `iceberg.web.page_views_v2`, use:: + + ALTER TABLE iceberg.web.page_views_v2 SET PROPERTIES (commit_retries = 6); + TRUNCATE ^^^^^^^^ diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java index 113da1c71d54a..60bb0e8e4ffb7 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergAbstractMetadata.java @@ -84,7 +84,9 @@ import org.apache.iceberg.Schema; import org.apache.iceberg.SchemaParser; import org.apache.iceberg.Table; +import org.apache.iceberg.TableProperties; import org.apache.iceberg.Transaction; +import org.apache.iceberg.UpdateProperties; import org.apache.iceberg.exceptions.NoSuchTableException; import org.apache.iceberg.types.Type; import org.apache.iceberg.types.TypeUtil; @@ -122,6 +124,7 @@ import static com.facebook.presto.iceberg.IcebergPartitionType.ALL; import static com.facebook.presto.iceberg.IcebergSessionProperties.getCompressionCodec; import static com.facebook.presto.iceberg.IcebergSessionProperties.isPushdownFilterEnabled; +import static com.facebook.presto.iceberg.IcebergTableProperties.COMMIT_RETRIES; import static com.facebook.presto.iceberg.IcebergTableProperties.DELETE_MODE; import static com.facebook.presto.iceberg.IcebergTableProperties.FILE_FORMAT_PROPERTY; import static com.facebook.presto.iceberg.IcebergTableProperties.FORMAT_VERSION; @@ -990,6 +993,28 @@ public OptionalLong metadataDelete(ConnectorSession session, ConnectorTableHandl return removeScanFiles(icebergTable, domainPredicate); } + @Override + public void setTableProperties(ConnectorSession session, ConnectorTableHandle tableHandle, Map properties) + { + IcebergTableHandle handle = (IcebergTableHandle) tableHandle; + Table icebergTable = getIcebergTable(session, handle.getSchemaTableName()); + transaction = icebergTable.newTransaction(); + + UpdateProperties updateProperties = transaction.updateProperties(); + for (Map.Entry entry : properties.entrySet()) { + switch (entry.getKey()) { + case COMMIT_RETRIES: + updateProperties.set(TableProperties.COMMIT_NUM_RETRIES, String.valueOf(entry.getValue())); + break; + default: + throw new PrestoException(NOT_SUPPORTED, "Updating property " + entry.getKey() + " is not supported currently"); + } + } + + updateProperties.commit(); + transaction.commitTransaction(); + } + /** * Deletes all the files for a specific predicate * diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java index 98bfef4aab872..57a8acfae41a6 100644 --- a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java +++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/IcebergDistributedSmokeTestBase.java @@ -52,6 +52,7 @@ import static java.util.stream.Collectors.joining; import static java.util.stream.IntStream.range; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertTrue; @@ -1808,4 +1809,46 @@ private Session sessionForTimezone(String zoneId, boolean legacyTimestamp) } return sessionBuilder.build(); } + + @Test + public void testUpdatingInvalidProperty() + { + Session session = getSession(); + String tableName = "test_invalid_property_update"; + assertUpdate(session, "CREATE TABLE " + tableName + " (c1 integer, c2 varchar) WITH(commit_retries = 4)"); + assertThatThrownBy(() -> assertUpdate("ALTER TABLE " + tableName + " SET PROPERTIES (format = 'PARQUET')")) + .hasMessage("Updating property format is not supported currently"); + assertUpdate("DROP TABLE " + tableName); + } + + @Test + public void testUpdatingRandomProperty() + { + Session session = getSession(); + String tableName = "test_random_property_update"; + assertUpdate(session, "CREATE TABLE " + tableName + " (c1 integer, c2 varchar) WITH(commit_retries = 4)"); + assertThatThrownBy(() -> assertUpdate("ALTER TABLE " + tableName + " SET PROPERTIES (some_config = 2)")) + .hasMessage("Catalog 'iceberg' does not support table property 'some_config'"); + assertUpdate("DROP TABLE " + tableName); + } + + @Test + public void testUpdatingCommitRetries() + { + Session session = getSession(); + String tableName = "test_commit_retries_update"; + assertUpdate(session, "CREATE TABLE " + tableName + " (c1 integer, c2 varchar) WITH(commit_retries = 4)"); + assertQuery("SELECT value FROM \"" + tableName + "$properties\" WHERE key = 'commit.retry.num-retries'", "VALUES 4"); + assertUpdate("ALTER TABLE " + tableName + " SET PROPERTIES (commit_retries = 5)"); + assertUpdate("ALTER TABLE IF EXISTS " + tableName + " SET PROPERTIES (commit_retries = 6)"); + assertQuery("SELECT value FROM \"" + tableName + "$properties\" WHERE key = 'commit.retry.num-retries'", "VALUES 6"); + assertUpdate("DROP TABLE " + tableName); + } + + @Test + public void testUpdateNonExistentTable() + { + assertQuerySucceeds("ALTER TABLE IF EXISTS non_existent_test_table1 SET PROPERTIES (commit_retries = 6)"); + assertQueryFails("ALTER TABLE non_existent_test_table2 SET PROPERTIES (commit_retries = 6)", "Table does not exist: iceberg.tpch.non_existent_test_table2"); + } }