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

Add support for table rename for delta lake with glue #13707

Merged

Conversation

homar
Copy link
Member

@homar homar commented Aug 17, 2022

Description

Is this change a fix, improvement, new feature, refactoring, or other?

new feature

Is this a change to the core query engine, a connector, client library, or the SPI interfaces? (be specific)

a connector

How would you describe this change to a non-technical end user or system administrator?

ALTER TABLE RENAME TO can be used with glue as a metastore for delta lake

Related issues, pull requests, and links

Fixes: #12985

Documentation

(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.

Release notes

( ) No release notes entries required.
(x) Release notes entries required with the following suggested text:

# Delta Lake
* Add support for `ALTER TABLE ... RENAME TO` statement on Glue metastore. ({issue}`12985`)

@cla-bot cla-bot bot added the cla-signed label Aug 17, 2022
@homar homar force-pushed the homar/delta_lake_with_glue_rename_table_support branch 4 times, most recently from 42928ae to cdd7429 Compare August 23, 2022 10:14
@findepi findepi requested review from ebyhr and alexjo2144 August 23, 2022 10:58
Copy link
Member

@alexjo2144 alexjo2144 left a comment

Choose a reason for hiding this comment

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

Just to be clear, this will not move any data files?

@@ -288,6 +289,8 @@
private final boolean deleteSchemaLocationsFallback;
private final boolean useUniqueTableLocation;

private final MetastoreTypeConfig metastoreTypeConfig;
Copy link
Member

Choose a reason for hiding this comment

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

Store the type itself, not the config

Suggested change
private final MetastoreTypeConfig metastoreTypeConfig;
private final String metastoreType;

@@ -1992,7 +1997,7 @@ public void renameTable(ConnectorSession session, ConnectorTableHandle tableHand
DeltaLakeTableHandle handle = (DeltaLakeTableHandle) tableHandle;
Table table = metastore.getTable(handle.getSchemaName(), handle.getTableName())
.orElseThrow(() -> new TableNotFoundException(handle.getSchemaTableName()));
if (table.getTableType().equals(MANAGED_TABLE.name())) {
if (table.getTableType().equals(MANAGED_TABLE.name()) && !metastoreTypeConfig.getMetastoreType().equals("glue")) {
Copy link
Member

Choose a reason for hiding this comment

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

equalsIgnoreCase

@homar homar force-pushed the homar/delta_lake_with_glue_rename_table_support branch from cdd7429 to 8c4467b Compare August 23, 2022 23:40
@homar
Copy link
Member Author

homar commented Aug 24, 2022

This failing suite is not related. It has been failing before on master https://github.com/trinodb/trino/runs/7976696676?check_suite_focus=true

#13825

@homar homar marked this pull request as ready for review August 24, 2022 12:11
@homar homar changed the title [WIP] Add support for table rename for delta lake with glue Add support for table rename for delta lake with glue Aug 24, 2022
@homar homar requested a review from alexjo2144 August 24, 2022 14:30
@homar
Copy link
Member Author

homar commented Aug 24, 2022

Just to be clear, this will not move any data files?

It should not

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

Can we update io.trino.plugin.hive.metastore.glue.TestHiveGlueMetastore#testRenameTable?

@homar
Copy link
Member Author

homar commented Aug 25, 2022

testRenameTable

Sorry I didn't notice this method

@homar homar force-pushed the homar/delta_lake_with_glue_rename_table_support branch 2 times, most recently from e0e52eb to 4782b6c Compare August 25, 2022 11:01
@homar
Copy link
Member Author

homar commented Aug 25, 2022

failure doesn't seem to be related

@@ -1996,7 +1999,8 @@ public void renameTable(ConnectorSession session, ConnectorTableHandle tableHand
DeltaLakeTableHandle handle = (DeltaLakeTableHandle) tableHandle;
Table table = metastore.getTable(handle.getSchemaName(), handle.getTableName())
.orElseThrow(() -> new TableNotFoundException(handle.getSchemaTableName()));
if (table.getTableType().equals(MANAGED_TABLE.name())) {
if (table.getTableType().equals(MANAGED_TABLE.name()) &&
!(metastoreType.equalsIgnoreCase("glue") || metastoreType.equalsIgnoreCase("file"))) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe include the metastore type in the exception msg

@@ -98,6 +102,7 @@ public DeltaLakeMetadataFactory(
this.perTransactionMetastoreCacheMaximumSize = deltaLakeConfig.getPerTransactionMetastoreCacheMaximumSize();
this.deleteSchemaLocationsFallback = deltaLakeConfig.isDeleteSchemaLocationsFallback();
this.useUniqueTableLocation = deltaLakeConfig.isUniqueTableLocation();
this.metastoreTypeConfig = requireNonNull(metastoreTypeConfig, "metastoreTypeConfig is null");
Copy link
Member

Choose a reason for hiding this comment

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

Reason we do this is that config classes are mutable and the metastore type cannot be changed dynamically. Realistically, this is not usually a problem but better to do it this way.

Suggested change
this.metastoreTypeConfig = requireNonNull(metastoreTypeConfig, "metastoreTypeConfig is null");
requireNonNull(metastoreTypeConfig, "metastoreTypeConfig is null");
this.metastoreType = metastoreTypeConfig.getMetastoreType();

public class TestDeltaLakeRenameToWithGlueMetastore
extends AbstractTestQueryFramework
{
protected static final String SCHEMA = "test_tables_with_custom_location" + randomTableSuffix();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
protected static final String SCHEMA = "test_tables_with_custom_location" + randomTableSuffix();
protected static final String SCHEMA = "test_delta_lake_rename_to_with_glue_" + randomTableSuffix();

@homar homar force-pushed the homar/delta_lake_with_glue_rename_table_support branch 3 times, most recently from 1f9c62e to a93d827 Compare August 27, 2022 21:31
@homar
Copy link
Member Author

homar commented Aug 28, 2022

@ebyhr I think this is a new test that is failing, it should not be related to my change I think you added it recently could you please take a look ?

@ebyhr
Copy link
Member

ebyhr commented Aug 28, 2022

Looking the failure. I will send a PR today.

@homar homar force-pushed the homar/delta_lake_with_glue_rename_table_support branch 3 times, most recently from 4c85271 to 6f47296 Compare August 29, 2022 15:59
@homar
Copy link
Member Author

homar commented Aug 30, 2022

@ebyhr can we merge this or do i need more changes?

@homar
Copy link
Member Author

homar commented Aug 30, 2022

Don't we need to copy partition indexes as well? It disappeared as far as I tested.

We never set them anywhere, for Iceberg we don't copy them either, what is more I don't see a way to obtain them. com.amazonaws.services.glue.model.Table doesn't contain them

@homar homar force-pushed the homar/delta_lake_with_glue_rename_table_support branch 4 times, most recently from bc2e89d to c92f31f Compare August 30, 2022 21:08
@ebyhr
Copy link
Member

ebyhr commented Aug 31, 2022

We never set them anywhere, for Iceberg we don't copy them either

Even if our connectors don't set partition indexes, users can directly set it in Glue and such index might be used when finding partitions in Hive tables.

what is more I don't see a way to obtain them. com.amazonaws.services.glue.model.Table doesn't contain them

We need to call AWSGlue#getPartitionIndexes to retrieve the information.

Anyway, you added a logic to deny Glue metastore in HiveMetadata.renameTable now. Let me take another look.

@homar
Copy link
Member Author

homar commented Aug 31, 2022

We never set them anywhere, for Iceberg we don't copy them either

Even if our connectors don't set partition indexes, users can directly set it in Glue and such index might be used when finding partitions in Hive tables.

what is more I don't see a way to obtain them. com.amazonaws.services.glue.model.Table doesn't contain them

We need to call AWSGlue#getPartitionIndexes to retrieve the information.

Oh that makes sense, I didn't know that, thanks.

Anyway, you added a logic to deny Glue metastore in HiveMetadata.renameTable now. Let me take another look.

Yes because it was not my intention to turn it on for Hive. I think that it would be hard as for hive it would make sense to actually move data to new location and for DeltaLAke and Iceberg we don't move that so it would be a totally different story

@homar homar force-pushed the homar/delta_lake_with_glue_rename_table_support branch from c92f31f to 30423e8 Compare August 31, 2022 13:58
@ebyhr ebyhr force-pushed the homar/delta_lake_with_glue_rename_table_support branch from 30423e8 to 43b174a Compare August 31, 2022 22:42
@ebyhr ebyhr merged commit cb9d67d into trinodb:master Sep 1, 2022
@ebyhr
Copy link
Member

ebyhr commented Sep 1, 2022

Merged, thanks!

@ebyhr ebyhr mentioned this pull request Sep 1, 2022
@github-actions github-actions bot added this to the 395 milestone Sep 1, 2022
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.

Delta Lake Glue support for ALTER TABLE RENAME TO
3 participants