Add support to redirect from a Hive catalog to an Iceberg catalog#4704
Add support to redirect from a Hive catalog to an Iceberg catalog#4704lxynov wants to merge 2 commits intotrinodb:masterfrom
Conversation
2b1d876 to
2832980
Compare
presto-main/src/main/java/io/prestosql/metadata/MetadataUtil.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/io/prestosql/execution/RenameTableTask.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/io/prestosql/execution/RenameViewTask.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
This could be written as
return getOptionalCatalogMetadata(session, tableName.getCatalogName())
.map(catalog -> {
CatalogName catalogName = catalog.getConnectorId(session, tableName);
ConnectorMetadata metadata = catalog.getMetadataFor(catalogName);
ConnectorSession connectorSession = session.toConnectorSession(catalogName);
return metadata.redirectCatalog(connectorSession, tableName.asSchemaTableName());
});There was a problem hiding this comment.
metadata.redirectCatalog(connectorSession, tableName.asSchemaTableName()) returns Optional<String> instead of String, making it difficult to follow the pattern here.
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveMetadata.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveMetadata.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveSessionProperties.java
Outdated
Show resolved
Hide resolved
|
This shouldn't be Iceberg specific. One could want to redirect to some other catalog for some other reasons. |
Add a catalog redirection method to connector SPI. It allows a connector to redirect to another catalog which may or may not use the same connector. Catalog redirection is tried whenever a table or view is accessed, e.g., in SELECT, INSERT, DROP TABLE, ALTER TABLE, GRANT, etc., queries. However, it's not tried with procedures. Multi-stop redirection without loop is allowed within a max depth.
2832980 to
90e02da
Compare
|
@electrum Thanks for the review. I've updated the PR |
@findepi People can implement the |
|
@lxynov great! I actually mean redirecting from hive to other connectors. |
|
I'm not sure it makes sense to be extensible at the user level. The redirection here is specific to Iceberg based on the Hive connector's knowledge that the table is an Iceberg table. If we had an HBase connector in addition to a Phoenix connector, it seems that the same level of specific knowledge would apply. |
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveConfig.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveSessionProperties.java
Outdated
Show resolved
Hide resolved
presto-hive/src/main/java/io/prestosql/plugin/hive/HiveSessionProperties.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/hive/TestHiveRedirectionToIceberg.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/hive/TestHiveRedirectionToIceberg.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/hive/TestHiveRedirectionToIceberg.java
Outdated
Show resolved
Hide resolved
presto-product-tests/src/main/java/io/prestosql/tests/hive/TestHiveRedirectionToIceberg.java
Outdated
Show resolved
Hide resolved
When enabled, Hive Connector would redirect a table access to an Iceberg catalog when the table is an Iceberg table.
90e02da to
aea5fdb
Compare
|
@electrum Thanks for the review! PR updated. The failing test seems unrelated. |
dain
left a comment
There was a problem hiding this comment.
Is there going to be a redirect Iceberg to Hive feature also?
| requireNonNull(tableName, "tableName is null"); | ||
|
|
||
| if (tableName.getCatalogName().isEmpty() || tableName.getSchemaName().isEmpty() || tableName.getObjectName().isEmpty()) { | ||
| return Optional.empty(); |
There was a problem hiding this comment.
I would expect this to be an error. Do we have cases where we do not have a fully qualified name?
| } | ||
|
|
||
| @Override | ||
| public Optional<String> redirectCatalog(Session session, QualifiedObjectName tableName) |
There was a problem hiding this comment.
I think this name might be too generic. I believe this only applies to the table namespace, and not procedures or functions. I suggest we make this clear, so we can add those is the future if needed.
| return new QualifiedObjectName(catalogName, schemaName, objectName); | ||
| } | ||
|
|
||
| public static QualifiedObjectName redirectToNewCatalogIfNecessary(Session session, QualifiedObjectName tableName, Metadata metadata) |
There was a problem hiding this comment.
Why not add this directly to Metadata and make redirectCatalog a private method on Metadata? I ask because I don't see any direct usages of redirectCatalog.
presto-spi/src/main/java/io/prestosql/spi/connector/ConnectorMetadata.java
Show resolved
Hide resolved
|
Replaced by #5160 |
Add catalog redirection support to SPI
Add a catalog redirection method to connector SPI. It allows a connector
to redirect to another catalog which may or may not use the same
connector.
Catalog redirection is tried whenever a table or view is accessed, e.g.,
in SELECT, INSERT, DROP TABLE, ALTER TABLE, GRANT, etc., queries. However,
it's not tried with procedures.
Multi-stop redirection without loop is allowed within a max depth.
Add support to redirect from Hive to an Iceberg catalog
When enabled, Hive Connector would redirect a table access to an Iceberg
catalog when the table is an Iceberg table.
Issue: #4442
Umbrella issue: #1324
Some notes:
show tables,select * from information_schema.columns) stay the same. They won't include results from other catalogs. Having said that, in the Hive/Iceberg case, a Hive catalog does include results of Iceberg tables inherently.