diff --git a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java index e1ad521f3d2dd..98f19c524258c 100644 --- a/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java +++ b/plugin/trino-hive/src/main/java/io/trino/plugin/hive/HiveMetadata.java @@ -2517,7 +2517,8 @@ public Optional getInsertLayout(ConnectorSession sessio } } // treat un-bucketed transactional table as having a single bucket on no columns - else if (hiveTableHandle.isInAcidTransaction()) { + // Note: we cannot use hiveTableHandle.isInAcidTransaction() here as transaction is not yet set in HiveTableHandle when getInsertLayout is called + else if (isFullAcidTable(table.getParameters())) { table = Table.builder(table) .withStorage(storage -> storage.setBucketProperty(Optional.of( new HiveBucketProperty(ImmutableList.of(), HiveBucketing.BucketingVersion.BUCKETING_V2, 1, ImmutableList.of())))) diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveTransactionalTable.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveTransactionalTable.java index 5272bc01bcd1f..2e5a8c419dd30 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveTransactionalTable.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestHiveTransactionalTable.java @@ -27,6 +27,7 @@ import io.trino.tests.product.hive.util.TemporaryHiveTable; import net.jodah.failsafe.Failsafe; import net.jodah.failsafe.RetryPolicy; +import org.assertj.core.api.Assertions; import org.testng.SkipException; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -540,7 +541,13 @@ public void testSimpleUnpartitionedTransactionalInsert() withTemporaryTable("unpartitioned_transactional_insert", true, false, NONE, tableName -> { onTrino().executeQuery(format("CREATE TABLE %s (column1 INT, column2 BIGINT) WITH (transactional = true)", tableName)); - onTrino().executeQuery(format("INSERT INTO %s VALUES (11, 100), (12, 200), (13, 300)", tableName)); + String insertQuery = format("INSERT INTO %s VALUES (11, 100), (12, 200), (13, 300)", tableName); + + // ensure that we treat ACID tables as implicitly bucketed on INSERT + String explainOutput = (String) onTrino().executeQuery("EXPLAIN " + insertQuery).row(0).get(0); + Assertions.assertThat(explainOutput).contains("Output partitioning: hive:HivePartitioningHandle{buckets=1"); + + onTrino().executeQuery(insertQuery); verifySelectForTrinoAndHive("SELECT * FROM " + tableName, "true", row(11, 100L), row(12, 200L), row(13, 300L));