diff --git a/presto-docs/src/main/sphinx/connector/iceberg.rst b/presto-docs/src/main/sphinx/connector/iceberg.rst index c019caa7ff781..4339f54b6c61a 100644 --- a/presto-docs/src/main/sphinx/connector/iceberg.rst +++ b/presto-docs/src/main/sphinx/connector/iceberg.rst @@ -477,6 +477,10 @@ Property Name Description ``write.update.mode`` Optionally specifies the write update mode of the Iceberg ``merge-on-read`` Yes No, write is not supported yet specification to use for new tables, either ``copy-on-write`` or ``merge-on-read``. + +``engine.hive.lock-enabled`` Whether to use Hive metastore locks when committing to Yes No + a Hive metastore + ======================================================== =============================================================== ===================== =================== ============================================= The table definition below specifies format ``ORC``, partitioning by columns ``c1`` and ``c2``, @@ -1495,8 +1499,13 @@ Use ``ARRAY[...]`` instead of a string to specify multiple partition transforms ALTER TABLE iceberg.web.page_views ADD COLUMN dt date WITH (partitioning = ARRAY['year', 'bucket(16)', 'identity']); -Some Iceberg table properties can be modified using an ALTER TABLE SET PROPERTIES statement. The modifiable table properties are -``commit.retry.num-retries``, ``read.split.target-size``, ``write.metadata.delete-after-commit.enabled``, and ``write.metadata.previous-versions-max``. +Some Iceberg table properties can be modified using an ``ALTER TABLE SET PROPERTIES`` statement. The modifiable table properties are: + +* ``commit.retry.num-retries`` +* ``read.split.target-size`` +* ``write.metadata.delete-after-commit.enabled`` +* ``engine.hive.lock-enabled`` +* ``write.metadata.previous-versions-max`` For example, to set ``commit.retry.num-retries`` to 6 for the table ``iceberg.web.page_views_v2``, use:: diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergTableProperties.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergTableProperties.java index 8a4473d94970d..1af10c5f31316 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergTableProperties.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergTableProperties.java @@ -29,6 +29,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.function.Function; @@ -44,6 +45,7 @@ import static java.lang.String.format; import static java.util.Locale.ENGLISH; import static org.apache.iceberg.TableProperties.COMMIT_NUM_RETRIES; +import static org.apache.iceberg.TableProperties.HIVE_LOCK_ENABLED; import static org.apache.iceberg.TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED; import static org.apache.iceberg.TableProperties.METRICS_MAX_INFERRED_COLUMN_DEFAULTS; import static org.apache.iceberg.TableProperties.UPDATE_MODE; @@ -112,6 +114,7 @@ public class IcebergTableProperties .add(METADATA_DELETE_AFTER_COMMIT) .add(METADATA_DELETE_AFTER_COMMIT_ENABLED) .add(METADATA_PREVIOUS_VERSIONS_MAX) + .add(HIVE_LOCK_ENABLED) .add(TableProperties.METADATA_PREVIOUS_VERSIONS_MAX) .build(); @@ -198,6 +201,11 @@ public IcebergTableProperties(IcebergConfig icebergConfig) "The maximum number of columns for which metrics are collected", icebergConfig.getMetricsMaxInferredColumn(), false)) + .add(booleanProperty( + HIVE_LOCK_ENABLED, + "Whether to enable hive locks", + null, + false)) .add(new PropertyMetadata<>( UPDATE_MODE, "Update mode for the table", @@ -298,6 +306,10 @@ public static String getWriteDataLocation(Map tableProperties) { return (String) tableProperties.get(WRITE_DATA_LOCATION); } + public static Optional isHiveLocksEnabled(Map tableProperties) + { + return tableProperties.containsKey(HIVE_LOCK_ENABLED) ? Optional.of(String.valueOf(tableProperties.get(HIVE_LOCK_ENABLED))) : Optional.empty(); + } public String getFormatVersion(ConnectorSession session, Map tableProperties) { diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java index ea55a189f4018..755968d2c0879 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/IcebergUtil.java @@ -146,6 +146,7 @@ import static com.facebook.presto.iceberg.IcebergSessionProperties.getCompressionCodec; import static com.facebook.presto.iceberg.IcebergSessionProperties.isMergeOnReadModeEnabled; import static com.facebook.presto.iceberg.IcebergTableProperties.getWriteDataLocation; +import static com.facebook.presto.iceberg.IcebergTableProperties.isHiveLocksEnabled; import static com.facebook.presto.iceberg.TypeConverter.toIcebergType; import static com.facebook.presto.iceberg.TypeConverter.toPrestoType; import static com.facebook.presto.iceberg.util.IcebergPrestoModelConverters.toIcebergTableIdentifier; @@ -191,6 +192,7 @@ import static org.apache.iceberg.TableProperties.DELETE_MODE; import static org.apache.iceberg.TableProperties.DELETE_MODE_DEFAULT; import static org.apache.iceberg.TableProperties.FORMAT_VERSION; +import static org.apache.iceberg.TableProperties.HIVE_LOCK_ENABLED; import static org.apache.iceberg.TableProperties.MERGE_MODE; import static org.apache.iceberg.TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED; import static org.apache.iceberg.TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED_DEFAULT; @@ -1210,6 +1212,8 @@ public static Map populateTableProperties(IcebergAbstractMetadat propertiesBuilder.put(SPLIT_SIZE, String.valueOf(IcebergTableProperties.getTargetSplitSize(tableMetadata.getProperties()))); + isHiveLocksEnabled(tableMetadata.getProperties()).ifPresent(value -> propertiesBuilder.put(HIVE_LOCK_ENABLED, value)); + return propertiesBuilder.build(); } diff --git a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/hive/TestIcebergDistributedHive.java b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/hive/TestIcebergDistributedHive.java index 6e0697f4ebb65..49a01ed705ff0 100644 --- a/presto-iceberg/src/test/java/com/facebook/presto/iceberg/hive/TestIcebergDistributedHive.java +++ b/presto-iceberg/src/test/java/com/facebook/presto/iceberg/hive/TestIcebergDistributedHive.java @@ -66,6 +66,7 @@ import static com.google.common.io.Files.createTempDir; import static java.lang.String.format; import static org.apache.iceberg.TableMetadata.newTableMetadata; +import static org.apache.iceberg.TableProperties.HIVE_LOCK_ENABLED; import static org.apache.iceberg.Transactions.createTableTransaction; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; @@ -115,6 +116,21 @@ public void testStatisticsFileCache() // so this test won't complete successfully. } + @Test + public void testCreateAlterTableWithHiveLocksDisabled() + { + assertQuerySucceeds("CREATE TABLE test_table(i int) WITH (\"engine.hive.lock-enabled\" = false)"); + assertEquals(getQueryRunner().execute("SELECT value FROM \"test_table$properties\" WHERE key = 'engine.hive.lock-enabled'").getOnlyValue(), + "false"); + assertQuerySucceeds("CREATE TABLE sample_table(i int)"); + assertEquals(getQueryRunner().execute("SELECT value FROM \"sample_table$properties\" WHERE key = 'engine.hive.lock-enabled'").getRowCount(), + 0); + assertUpdate("ALTER TABLE sample_table SET PROPERTIES(\"engine.hive.lock-enabled\" = false)"); + + assertEquals(getQueryRunner().execute("SELECT value FROM \"sample_table$properties\" WHERE key = 'engine.hive.lock-enabled'").getOnlyValue(), + "false"); + } + @Test public void testManifestFileCaching() throws Exception @@ -220,6 +236,7 @@ public void testCommitTableMetadataForNoLock() { createTable("iceberg-test-table", createTempDir().toURI().toString(), ImmutableMap.of("engine.hive.lock-enabled", "false"), 2); BaseTable table = (BaseTable) loadTable("iceberg-test-table"); + assertEquals(table.properties().get(HIVE_LOCK_ENABLED), "false"); HiveTableOperations operations = (HiveTableOperations) table.operations(); TableMetadata currentMetadata = operations.current();