Skip to content

Commit

Permalink
Wrap iceberg table/view not exist exception as TableNotFoundException
Browse files Browse the repository at this point in the history
  • Loading branch information
hantangwangd committed Nov 20, 2024
1 parent 9f490e7 commit 8c0b38b
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.apache.iceberg.Table;
import org.apache.iceberg.Transaction;
import org.apache.iceberg.exceptions.NoSuchTableException;
import org.apache.iceberg.exceptions.NoSuchViewException;
import org.apache.iceberg.types.Type;
import org.apache.iceberg.types.TypeUtil;
import org.apache.iceberg.types.Types;
Expand Down Expand Up @@ -396,8 +397,9 @@ public ConnectorTableMetadata getTableMetadata(ConnectorSession session, Connect

protected ConnectorTableMetadata getTableOrViewMetadata(ConnectorSession session, SchemaTableName table, IcebergTableName icebergTableName)
{
SchemaTableName schemaTableName = new SchemaTableName(table.getSchemaName(), icebergTableName.getTableName());
try {
Table icebergTable = getIcebergTable(session, new SchemaTableName(table.getSchemaName(), icebergTableName.getTableName()));
Table icebergTable = getIcebergTable(session, schemaTableName);
ImmutableList.Builder<ColumnMetadata> columns = ImmutableList.builder();
columns.addAll(getColumnMetadata(icebergTable));
if (icebergTableName.getTableType() == CHANGELOG) {
Expand All @@ -409,12 +411,17 @@ protected ConnectorTableMetadata getTableOrViewMetadata(ConnectorSession session
}
return new ConnectorTableMetadata(table, columns.build(), createMetadataProperties(icebergTable), getTableComment(icebergTable));
}
catch (NoSuchTableException e) {
catch (NoSuchTableException noSuchTableException) {
// Considering that the Iceberg library does not provide an efficient way to determine whether
// it's a view or a table without loading it, we first try to load it as a table directly, and then
// try to load it as a view when getting an `NoSuchTableException`. This will be more efficient.
View icebergView = getIcebergView(session, new SchemaTableName(table.getSchemaName(), icebergTableName.getTableName()));
return new ConnectorTableMetadata(table, getColumnMetadata(icebergView), createViewMetadataProperties(icebergView), getViewComment(icebergView));
try {
View icebergView = getIcebergView(session, schemaTableName);
return new ConnectorTableMetadata(table, getColumnMetadata(icebergView), createViewMetadataProperties(icebergView), getViewComment(icebergView));
}
catch (NoSuchViewException noSuchViewException) {
throw new TableNotFoundException(schemaTableName);
}
}
}

Expand Down

0 comments on commit 8c0b38b

Please sign in to comment.