From bbe7fd4cecf745325f48b383b6f86e360ea7d42b Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Wed, 28 Jul 2021 09:52:52 +0200 Subject: [PATCH] Avoid redundant metastore calls for non-system Iceberg tables When table name doesn't look like a system table, we can exit early. --- .../io/trino/plugin/iceberg/IcebergMetadata.java | 4 ++++ .../TestIcebergMetastoreAccessOperations.java | 16 ++++++++-------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java index a9cee57b0d3f..759a37ae380a 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java @@ -303,6 +303,9 @@ public Optional getSystemTable(ConnectorSession session, SchemaTabl private Optional getRawSystemTable(ConnectorSession session, SchemaTableName tableName) { IcebergTableName name = IcebergTableName.from(tableName.getTableName()); + if (name.getTableType() == DATA) { + return Optional.empty(); + } Optional hiveTable = metastore.getTable(new HiveIdentity(session), tableName.getSchemaName(), name.getTableName()); if (hiveTable.isEmpty() || !isIcebergTable(hiveTable.get())) { @@ -314,6 +317,7 @@ private Optional 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()) { diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java index f2cfb9be3e5d..5d4741ef022f 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergMetastoreAccessOperations.java @@ -83,7 +83,7 @@ public void testCreateTable() ImmutableMultiset.builder() .add(CREATE_TABLE) .add(GET_DATABASE) - .addCopies(GET_TABLE, 2) + .add(GET_TABLE) .build()); } @@ -94,7 +94,7 @@ public void testCreateTableAsSelect() ImmutableMultiset.builder() .add(GET_DATABASE) .add(CREATE_TABLE) - .addCopies(GET_TABLE, 2) + .add(GET_TABLE) .build()); } @@ -105,7 +105,7 @@ public void testSelect() assertMetastoreInvocations("SELECT * FROM test_select_from", ImmutableMultiset.builder() - .addCopies(GET_TABLE, 12) + .addCopies(GET_TABLE, 8) .build()); } @@ -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()); } @@ -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()); } @@ -139,7 +139,7 @@ public void testExplainSelect() assertMetastoreInvocations("EXPLAIN SELECT * FROM test_explain", ImmutableMultiset.builder() - .addCopies(GET_TABLE, 11) + .addCopies(GET_TABLE, 7) .build()); } @@ -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()); } @@ -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()); }