Skip to content

Commit

Permalink
Short-circuit HiveMetadata.redirectTable when redirects not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jul 20, 2023
1 parent ad29149 commit 4b4bb6f
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3758,6 +3758,15 @@ public Optional<CatalogSchemaTableName> redirectTable(ConnectorSession session,
{
requireNonNull(session, "session is null");
requireNonNull(tableName, "tableName is null");

Optional<String> icebergCatalogName = getIcebergCatalogName(session);
Optional<String> deltaLakeCatalogName = getDeltaLakeCatalogName(session);
Optional<String> hudiCatalogName = getHudiCatalogName(session);

if (icebergCatalogName.isEmpty() && deltaLakeCatalogName.isEmpty() && hudiCatalogName.isEmpty()) {
return Optional.empty();
}

if (isHiveSystemSchema(tableName.getSchemaName())) {
return Optional.empty();
}
Expand All @@ -3768,9 +3777,10 @@ public Optional<CatalogSchemaTableName> redirectTable(ConnectorSession session,
return Optional.empty();
}

Optional<CatalogSchemaTableName> catalogSchemaTableName = redirectTableToIceberg(session, table.get())
.or(() -> redirectTableToDeltaLake(session, table.get()))
.or(() -> redirectTableToHudi(session, table.get()));
Optional<CatalogSchemaTableName> catalogSchemaTableName = Optional.<CatalogSchemaTableName>empty()
.or(() -> redirectTableToIceberg(icebergCatalogName, table.get()))
.or(() -> redirectTableToDeltaLake(deltaLakeCatalogName, table.get()))
.or(() -> redirectTableToHudi(hudiCatalogName, table.get()));

// stitch back the suffix we cut off.
return catalogSchemaTableName.map(name -> new CatalogSchemaTableName(
Expand All @@ -3780,9 +3790,8 @@ public Optional<CatalogSchemaTableName> redirectTable(ConnectorSession session,
name.getSchemaTableName().getTableName() + tableNameSplit.getSuffix().orElse(""))));
}

private Optional<CatalogSchemaTableName> redirectTableToIceberg(ConnectorSession session, Table table)
private Optional<CatalogSchemaTableName> redirectTableToIceberg(Optional<String> targetCatalogName, Table table)
{
Optional<String> targetCatalogName = getIcebergCatalogName(session);
if (targetCatalogName.isEmpty()) {
return Optional.empty();
}
Expand All @@ -3792,9 +3801,8 @@ private Optional<CatalogSchemaTableName> redirectTableToIceberg(ConnectorSession
return Optional.empty();
}

private Optional<CatalogSchemaTableName> redirectTableToDeltaLake(ConnectorSession session, Table table)
private Optional<CatalogSchemaTableName> redirectTableToDeltaLake(Optional<String> targetCatalogName, Table table)
{
Optional<String> targetCatalogName = getDeltaLakeCatalogName(session);
if (targetCatalogName.isEmpty()) {
return Optional.empty();
}
Expand All @@ -3804,9 +3812,8 @@ private Optional<CatalogSchemaTableName> redirectTableToDeltaLake(ConnectorSessi
return Optional.empty();
}

private Optional<CatalogSchemaTableName> redirectTableToHudi(ConnectorSession session, Table table)
private Optional<CatalogSchemaTableName> redirectTableToHudi(Optional<String> targetCatalogName, Table table)
{
Optional<String> targetCatalogName = getHudiCatalogName(session);
if (targetCatalogName.isEmpty()) {
return Optional.empty();
}
Expand Down

0 comments on commit 4b4bb6f

Please sign in to comment.