Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of inserting into non-bucketed ACID tables #8899

Merged
merged 1 commit into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,8 @@ public Optional<ConnectorNewTableLayout> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this?
I can see that we do set the transaction in the HiveInsertTableHandle in beginInsert.

Is it because the engine calls getInsertLayout during planning (i.e. before execution when beginInsert would be called?)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other existing use I can see of the method is in

checkArgument(hiveTableHandle.isInAcidTransaction(), "Not in a transaction; hiveTableHandle: %s", hiveTableHandle);
which seems to be okay.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because the engine calls getInsertLayout during planning (i.e. before execution when beginInsert would be called?)?

Yeah - exactly. We are operating on TableHandle which is obtained by HiveMetadata.getTableHandle here. And the transaction field is set to NO_ACID_TRANSACTION there.

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()))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
hashhar marked this conversation as resolved.
Show resolved Hide resolved

onTrino().executeQuery(insertQuery);

verifySelectForTrinoAndHive("SELECT * FROM " + tableName, "true", row(11, 100L), row(12, 200L), row(13, 300L));

Expand Down