Skip to content

Commit

Permalink
Avoid redundant metastore calls for non-system Iceberg tables
Browse files Browse the repository at this point in the history
When table name doesn't look like a system table, we can exit early.
  • Loading branch information
findepi committed Jul 28, 2021
1 parent bda8eb5 commit d29fcd9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public Optional<SystemTable> getSystemTable(ConnectorSession session, SchemaTabl
private Optional<SystemTable> getRawSystemTable(ConnectorSession session, SchemaTableName tableName)
{
IcebergTableName name = IcebergTableName.from(tableName.getTableName());
if (name.getTableType() == DATA) {
return Optional.empty();
}

Optional<Table> hiveTable = metastore.getTable(new HiveIdentity(session), tableName.getSchemaName(), name.getTableName());
if (hiveTable.isEmpty() || !isIcebergTable(hiveTable.get())) {
Expand All @@ -314,6 +317,7 @@ private Optional<SystemTable> getRawSystemTable(ConnectorSession session, Schema
SchemaTableName systemTableName = new SchemaTableName(tableName.getSchemaName(), name.getTableNameWithType());
switch (name.getTableType()) {
case DATA:
// Handled above.
break;
case HISTORY:
if (name.getSnapshotId().isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void testCreateTable()
ImmutableMultiset.builder()
.add(CREATE_TABLE)
.add(GET_DATABASE)
.addCopies(GET_TABLE, 2)
.add(GET_TABLE)
.build());
}

Expand All @@ -94,7 +94,7 @@ public void testCreateTableAsSelect()
ImmutableMultiset.builder()
.add(GET_DATABASE)
.add(CREATE_TABLE)
.addCopies(GET_TABLE, 2)
.add(GET_TABLE)
.build());
}

Expand All @@ -105,7 +105,7 @@ public void testSelect()

assertMetastoreInvocations("SELECT * FROM test_select_from",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 12)
.addCopies(GET_TABLE, 8)
.build());
}

Expand All @@ -116,7 +116,7 @@ public void testSelectWithFilter()

assertMetastoreInvocations("SELECT * FROM test_select_from_where WHERE age = 2",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 12)
.addCopies(GET_TABLE, 8)
.build());
}

Expand All @@ -128,7 +128,7 @@ public void testJoin()

assertMetastoreInvocations("SELECT name, age FROM test_join_t1 JOIN test_join_t2 ON test_join_t2.id = test_join_t1.id",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 24)
.addCopies(GET_TABLE, 16)
.build());
}

Expand All @@ -139,7 +139,7 @@ public void testExplainSelect()

assertMetastoreInvocations("EXPLAIN SELECT * FROM test_explain",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 11)
.addCopies(GET_TABLE, 7)
.build());
}

Expand All @@ -150,7 +150,7 @@ public void testShowStatsForTable()

assertMetastoreInvocations("SHOW STATS FOR test_show_stats",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 9)
.addCopies(GET_TABLE, 5)
.build());
}

Expand All @@ -161,7 +161,7 @@ public void testShowStatsForTableWithFilter()

assertMetastoreInvocations("SHOW STATS FOR (SELECT * FROM test_show_stats_with_filter where age >= 2)",
ImmutableMultiset.builder()
.addCopies(GET_TABLE, 9)
.addCopies(GET_TABLE, 5)
.build());
}

Expand Down

0 comments on commit d29fcd9

Please sign in to comment.