Skip to content

Commit

Permalink
Suppress metadata errors during views listing
Browse files Browse the repository at this point in the history
  • Loading branch information
pajaks authored and findepi committed Apr 29, 2024
1 parent 1eba06b commit e2b0b05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1401,9 +1401,16 @@ public Map<QualifiedObjectName, ViewInfo> getViews(Session session, QualifiedTab

Map<SchemaTableName, ConnectorViewDefinition> viewMap;
if (tablePrefix.getTable().isPresent()) {
viewMap = metadata.getView(connectorSession, tablePrefix.toSchemaTableName())
.map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view))
.orElse(ImmutableMap.of());
try {
viewMap = metadata.getView(connectorSession, tablePrefix.toSchemaTableName())
.map(view -> ImmutableMap.of(tablePrefix.toSchemaTableName(), view))
.orElse(ImmutableMap.of());
}
catch (RuntimeException e) {
handleListingError(e, prefix);
// Empty in case of metadata error.
viewMap = ImmutableMap.of();
}
}
else {
viewMap = metadata.getViews(connectorSession, tablePrefix.getSchema());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ private void testFailingHiveViewsWithInformationSchema()
assertThat(onTrino().executeQuery("SELECT table_name FROM information_schema.views WHERE table_schema = 'test_list_failing_views' AND table_name = 'correct_view'"))
.containsOnly(row("correct_view"));

// Listing fails when metadata for the problematic view is queried specifically
assertThatThrownBy(() -> onTrino().executeQuery("SELECT table_name FROM information_schema.views WHERE table_schema = 'test_list_failing_views' AND table_name = 'failing_view'"))
.hasMessageContaining("Failed to translate Hive view 'test_list_failing_views.failing_view'");
assertThat(onTrino().executeQuery("SELECT table_name FROM information_schema.views WHERE table_schema = 'test_list_failing_views' AND table_name = 'failing_view'"))
.hasNoRows();

// Queries on information_schema.columns also trigger ConnectorMetadata#getViews. Columns from failing_view are
// listed too since HiveMetadata#listTableColumns does not ignore Hive views.
Expand Down Expand Up @@ -151,6 +150,10 @@ private static void setupBrokenView()
onTrino().executeQuery("CREATE TABLE test_list_failing_views.table_dropped (col0 BIGINT)");
onHive().executeQuery("CREATE VIEW test_list_failing_views.failing_view AS SELECT * FROM test_list_failing_views.table_dropped");
onTrino().executeQuery("DROP TABLE test_list_failing_views.table_dropped");

// Make sure that failing_view throws exception when queried explicitly.
assertThatThrownBy(() -> onTrino().executeQuery("SELECT * FROM test_list_failing_views.failing_view"))
.hasMessageContaining("Failed to translate Hive view 'test_list_failing_views.failing_view'");
}

@Test
Expand Down

0 comments on commit e2b0b05

Please sign in to comment.