Add support for storing metadata to metastore in Delta Lake#21463
Add support for storing metadata to metastore in Delta Lake#21463ebyhr merged 6 commits intotrinodb:masterfrom
Conversation
29de71c to
374a418
Compare
|
Pls rebase to deal with code conflicts. |
findinpath
left a comment
There was a problem hiding this comment.
Looks very promissing !!!
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConfig.java
Outdated
Show resolved
Hide resolved
...n/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/metastore/DeltaLakeMetastore.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
We need compatibility tests with Delta Lake OSS where Spark writes to the table and Trino is constrained to update the metadata caching properties on any read/write operation.
8785fd6 to
0fc669a
Compare
|
Addressed comments partially. I will add more tests to TestDeltaLakeMetastoreAccessOperations. |
plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/DeltaLakeQueryRunner.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
3cb75c9 to
0d7fdfd
Compare
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
...src/main/java/io/trino/plugin/deltalake/metastore/HiveMetastoreBackedDeltaLakeMetastore.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeConnectorTest.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
...src/main/java/io/trino/plugin/deltalake/metastore/HiveMetastoreBackedDeltaLakeMetastore.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Have you taken into consideration base64(compress(schema))?
There was a problem hiding this comment.
Good question.
Regardless of whether we compress or not, we should have a check on length.
...in/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeFileOperations.java
Outdated
Show resolved
Hide resolved
303cf68 to
050edfa
Compare
There was a problem hiding this comment.
In case of referencing multiple times the same table in a query, is this check supposed to avoid calling metastore table replace repeatedly for the same table?
I don't follow where we ensure that the call is made only once.
I'm thinking that this should be ensured with the help of a ConcurrentMap like in io.trino.plugin.deltalake.DeltaLakeMetadata#getSnapshot(io.trino.spi.connector.ConnectorSession, io.trino.spi.connector.SchemaTableName, java.lang.String, java.util.Optional<java.lang.Long>)
There was a problem hiding this comment.
I don't follow where we ensure that the call is made only once.
good point. i don't think we do
we should maintain a sort of a queue of pending updates
and scheduling new update logically remove previous entry
the ordering of updates doesn't matter (we can deliver them out of order, as long as we deduplicate), and we want to deduplicate, so we only need a Map<SchemaTableName, /* update info */>
Moreover, the update should be propagated to the metastore after transaction is committed.
Thus
- DeltaLakeMetadata should collect stuff to update (there shouldn't be any duplicates here, as DeltaLakeMetadata should not observe two different versions of one table, unless AS OF is used0)
- on commit, it should move the collected stuff to update to update manager singleton, to perform actual update
- the update manager should deduplicate (updates coming from different transactions) and perform actual updates
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConfig.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
I don't follow where we ensure that the call is made only once.
good point. i don't think we do
we should maintain a sort of a queue of pending updates
and scheduling new update logically remove previous entry
the ordering of updates doesn't matter (we can deliver them out of order, as long as we deduplicate), and we want to deduplicate, so we only need a Map<SchemaTableName, /* update info */>
Moreover, the update should be propagated to the metastore after transaction is committed.
Thus
- DeltaLakeMetadata should collect stuff to update (there shouldn't be any duplicates here, as DeltaLakeMetadata should not observe two different versions of one table, unless AS OF is used0)
- on commit, it should move the collected stuff to update to update manager singleton, to perform actual update
- the update manager should deduplicate (updates coming from different transactions) and perform actual updates
There was a problem hiding this comment.
This looks like efficient operation, but it's not good API at least for Glue. Getting table names is as expensive as getting all table information (because that's what's happening under the covers)
We should add something like HiveMetastore.streamTables that would return full table objects in an iterative manner. I happen to have something like that implemented, so I can share the code later. For now, we can just use listTables, without extracting new streamTables method.
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
...rc/test/java/io/trino/plugin/deltalake/metastore/TestDeltaLakeMetastoreAccessOperations.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
And without cache, we do only GET_TABLE, right?
would it be possible to have "do cache metadata" as a boolean variable in the test
so that the expected can be expressed as a conditional expression based on "do cache metadata"? this would make the test tell the story more directly
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeModule.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeModule.java
Outdated
Show resolved
Hide resolved
050edfa to
7114f75
Compare
|
Just rebased on master to resolve conflicts. (No change) |
810d795 to
57d174d
Compare
...ava/io/trino/plugin/deltalake/metastore/glue/v1/DeltaLakeGlueV1MetastoreTableOperations.java
Outdated
Show resolved
Hide resolved
...ava/io/trino/plugin/deltalake/metastore/glue/v1/DeltaLakeGlueV1MetastoreTableOperations.java
Outdated
Show resolved
Hide resolved
65c0f8e to
e1e35b9
Compare
|
Rebased on master to resolve logical conflicts. |
71390ac to
69b1e5a
Compare
69b1e5a to
ecaa8e7
Compare
|
Rebased on master to resolve conflicts. |
There was a problem hiding this comment.
unrelated question: Why is ThreadContextClassLoader required for metadata.commit()?
There was a problem hiding this comment.
probably to ensure that metadata.commit() call will be executed in the context of the delta lake plugin classloader
|
@wendigo Please take another look. |
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConfig.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConfig.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeConfig.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
...in/trino-delta-lake/src/test/java/io/trino/plugin/deltalake/TestDeltaLakeFileOperations.java
Outdated
Show resolved
Hide resolved
8295cc1 to
537164b
Compare
plugin/trino-delta-lake/src/main/java/io/trino/plugin/deltalake/DeltaLakeMetadata.java
Outdated
Show resolved
Hide resolved
This is preparatory change for the next commit that stores the table definition to metastore.
3afd97a to
e010a3d
Compare
e010a3d to
33f8454
Compare
Description
This PR adds a new
delta.metastore.store-table-metadataconfig property (true by default) and stores the last transaction number and schema string to table parameter on the metastore when the property is enabled.Conditions we update the metastore:
The cached information is used when listing table comments or columns.
Test result with 100 tables having 7 transaction logs:
We could improve more once we use Glue specific API call (AWSGlue#getTables). This can be handled in follow-up.
Release notes
(x) Release notes are required, with the following suggested text: