From 0deb8008a8607ac6b828ea0da21cf6b2b67f66ca Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Thu, 19 Oct 2023 04:33:03 -0400 Subject: [PATCH] Enable writing to full ACID tables in Hive connector when the table has no partitions --- .../main/java/io/trino/plugin/hive/HiveMetadata.java | 6 +++++- .../hive/TestWriteToHiveTransactionalTableInTrino.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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 b8c0f6862a75..02468bcc1665 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 @@ -2131,7 +2131,11 @@ public Optional finishInsert(ConnectorSession session, if (isFullAcidTable(table.getParameters())) { for (PartitionUpdate update : partitionUpdates) { String deltaSubdir = deltaSubdir(handle.getTransaction().getWriteId(), 0); - String directory = "%s/%s/%s".formatted(table.getStorage().getLocation(), update.getName(), deltaSubdir); + String directory = table.getStorage().getLocation(); + if (!update.getName().isEmpty()) { + directory += "/" + update.getName(); + } + directory += "/" + deltaSubdir; createOrcAcidVersionFile(session.getIdentity(), directory); } } diff --git a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestWriteToHiveTransactionalTableInTrino.java b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestWriteToHiveTransactionalTableInTrino.java index 591f4a4b98d2..93947638d2ef 100644 --- a/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestWriteToHiveTransactionalTableInTrino.java +++ b/testing/trino-product-tests/src/main/java/io/trino/tests/product/hive/TestWriteToHiveTransactionalTableInTrino.java @@ -46,6 +46,16 @@ public void testInsertIntoPartitionedTable() onTrino().executeQuery(format("DROP TABLE %s", tableName)); } + @Test(groups = {HMS_ONLY, PROFILE_SPECIFIC_TESTS}) + public void testInsertIntoNonPartitionedTable() + { + String tableName = "non_partitioned_transactional_insert"; + onTrino().executeQuery(format("CREATE TABLE %s (column1 INT, column2 INT) WITH (transactional = true)", tableName)); + onTrino().executeQuery(format("INSERT INTO %s VALUES (11, 12), (111, 121)", tableName)); + assertThat(onTrino().executeQuery(format("SELECT * FROM %s", tableName))).containsOnly(row(11, 12), row(111, 121)); + onTrino().executeQuery(format("DROP TABLE %s", tableName)); + } + @Test(groups = {HMS_ONLY, PROFILE_SPECIFIC_TESTS}) public void testUpdateOnUnpartitionedTable() {