Skip to content

Commit

Permalink
Fix formatting and simplify condition in HiveMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
electrum committed Mar 22, 2023
1 parent 9c4ef0e commit d1d465e
Showing 1 changed file with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -804,35 +804,38 @@ public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSess
throw new UnsupportedOperationException("The deprecated listTableColumns is not supported because streamTableColumns is implemented instead");
}

@SuppressWarnings("TryWithIdenticalCatches")
@Override
public Iterator<TableColumnsMetadata> streamTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
requireNonNull(prefix, "prefix is null");
return listTables(session, prefix).stream().flatMap(tableName -> {
try {
if (redirectTable(session, tableName).isPresent()) {
return Stream.of(TableColumnsMetadata.forRedirectedTable(tableName));
}
return Stream.of(TableColumnsMetadata.forTable(tableName, getTableMetadata(session, tableName).getColumns()));
}
catch (HiveViewNotSupportedException e) {
// view is not supported
return Stream.empty();
}
catch (TableNotFoundException e) {
// table disappeared during listing operation
return Stream.empty();
return listTables(session, prefix).stream()
.flatMap(tableName -> streamTableColumns(session, tableName))
.iterator();
}

private Stream<TableColumnsMetadata> streamTableColumns(ConnectorSession session, SchemaTableName tableName)
{
try {
if (redirectTable(session, tableName).isPresent()) {
return Stream.of(TableColumnsMetadata.forRedirectedTable(tableName));
}
catch (TrinoException e) {
// Skip this table if there's a failure due to Hive, a bad Serde, or bad metadata
if (!e.getErrorCode().getType().equals(ErrorType.EXTERNAL)) {
throw e;
}
return Stream.of(TableColumnsMetadata.forTable(tableName, getTableMetadata(session, tableName).getColumns()));
}
catch (HiveViewNotSupportedException e) {
// view is not supported
return Stream.empty();
}
catch (TableNotFoundException e) {
// table disappeared during listing operation
return Stream.empty();
}
catch (TrinoException e) {
// Skip this table if there's a failure due to Hive, a bad Serde, or bad metadata
if (e.getErrorCode().getType() == ErrorType.EXTERNAL) {
return Stream.empty();
}
})
.iterator();
throw e;
}
}

@Override
Expand Down

0 comments on commit d1d465e

Please sign in to comment.