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

Do not create temporary staging path for CREATE TABLE statement #14830

Merged
merged 1 commit into from
Nov 14, 2022

Conversation

weijiii
Copy link
Member

@weijiii weijiii commented Oct 30, 2022

Description

I am continuing the work in #5802 .
The issue is that both CREATE TABLE and CREATE TABLE AS ... use forNewTable to generate a LocationHandle. In subsequent operations the directory created for CREATE TABLE is never renamed as the target directory because there was no data written to it.
The solution is to not create any temporary staging directory for CREATE TABLE operations. As suggested by the previous discussion I decided to create a new API forNewTableAsSelect in LocationService, and modify the original forNewTable to not create any temporary staging directory as it should.

Non-technical explanation

Currently during CREATE TABLE operation, Trino creates a unnecessary directory that is not used and cleaned up afterwards. This patch will fix this issue.

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:

@weijiii
Copy link
Member Author

weijiii commented Oct 30, 2022

cc: @phd3

@weijiii weijiii force-pushed the create_table_without_data branch 2 times, most recently from 50a62c3 to 149d23e Compare October 31, 2022 01:40
@weijiii weijiii changed the title Create table without data Do not create temporary staging path for CREATE TABLE statement Oct 31, 2022
@phd3 phd3 self-requested a review October 31, 2022 20:55
@weijiii weijiii force-pushed the create_table_without_data branch 2 times, most recently from 8c9edbb to 4c09730 Compare November 2, 2022 08:57
@@ -27,6 +27,8 @@
{
LocationHandle forNewTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, String schemaName, String tableName, Optional<Path> externalLocation);
Copy link
Member

Choose a reason for hiding this comment

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

l'd simplify this as below - as we don't care about external location anyway.

Path forNewTable(SemiTransactionalHiveMetastore metastore, ConnectorSession session, String schemaName, String tableName);

Comment on lines 3008 to 3009
.setBucketProperty(Optional.empty())
.setSerdeParameters(ImmutableMap.of());
Copy link
Member

Choose a reason for hiding this comment

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

nit: if nothing specific being set - better to remove as this is default ?

PRESTO_VERSION_NAME, TEST_SERVER_VERSION,
PRESTO_QUERY_ID_NAME, session.getQueryId()))
.setDataColumns(columns)
.setPartitionColumns(ImmutableList.of());
Copy link
Member

Choose a reason for hiding this comment

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

remove?

.setStorageFormat(StorageFormat.create(storageFormat.getSerde(), storageFormat.getInputFormat(), storageFormat.getOutputFormat()))
.setBucketProperty(Optional.empty())
.setSerdeParameters(ImmutableMap.of());
PrincipalPrivileges principalPrivileges = testingPrincipalPrivilege(tableOwner, session.getUser());
Copy link
Member

Choose a reason for hiding this comment

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

nit: inline

.setBucketProperty(Optional.empty())
.setSerdeParameters(ImmutableMap.of());
PrincipalPrivileges principalPrivileges = testingPrincipalPrivilege(tableOwner, session.getUser());
transaction.getMetastore().createTable(session, tableBuilder.build(), principalPrivileges, Optional.empty(), Optional.empty(), true, EMPTY_TABLE_STATISTICS, false);
Copy link
Member

Choose a reason for hiding this comment

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

nit: split args once above is inlined

Copy link
Member Author

@weijiii weijiii Nov 4, 2022

Choose a reason for hiding this comment

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

@phd3 I'll address these comments in next revision.

Copy link
Member Author

Choose a reason for hiding this comment

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

@phd3 I have made changes according to your comments above. Please take a look when you have time. Thanks!

Copy link
Member Author

@weijiii weijiii Nov 8, 2022

Choose a reason for hiding this comment

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

IIUC this comment is suggesting to change split the arguments of the method call on line 3011 to separate lines with principalPrivileges inlined.

@weijiii weijiii force-pushed the create_table_without_data branch 3 times, most recently from 967e690 to dc98ad6 Compare November 7, 2022 20:52
Copy link
Member

@phd3 phd3 left a comment

Choose a reason for hiding this comment

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

lgtm, just one comment

@@ -341,6 +341,8 @@

protected static final String TEST_SERVER_VERSION = "test_version";

protected static final String FIXED_TEMPORARY_STAGING_PREFIX = "fixed-hive-staging-prefix";
Copy link
Member

Choose a reason for hiding this comment

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

I'd actually use a test-local prefix (with a random suffix) - as any reuse of this static variable in future tests can potentially break the assertion

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense; I'll make the change.

Copy link
Member Author

Choose a reason for hiding this comment

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

@phd3 I've addressed this change in the new commit. Please take a look when you have time. Thanks!

@weijiii weijiii force-pushed the create_table_without_data branch from dc98ad6 to 3e85252 Compare November 14, 2022 04:29
@weijiii weijiii force-pushed the create_table_without_data branch from 3e85252 to 792310e Compare November 14, 2022 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants