Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hive: Optimize tableExists API in hive catalog #11597

Merged
merged 11 commits into from
Dec 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,26 @@ private void validateTableIsIcebergTableOrView(
}
}

@Override
public boolean tableExists(TableIdentifier identifier) {
if (!isValidIdentifier(identifier)) {
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved

String database = identifier.namespace().level(0);
try {
Table table = clients.run(client -> client.getTable(database, identifier.name()));
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved
HiveOperationsBase.validateTableIsIceberg(table, fullTableName(name, identifier));
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved
return true;
} catch (NoSuchTableException | NoSuchObjectException e) {
return false;
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved
} catch (TException e) {
throw new RuntimeException("Failed to check table existence of " + identifier, e);
} catch (InterruptedException e) {
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved
throw new RuntimeException("Interrupted in call to check table existence", e);
}
}

@Override
public void createNamespace(Namespace namespace, Map<String, String> meta) {
Preconditions.checkArgument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public void testHiveTableAndIcebergTableWithSameName(TableType tableType)
.containsExactly(TABLE_IDENTIFIER, identifier);
catalog.setListAllTables(false); // reset to default.

// create an iceberg table with the same name
// create an iceberg table with name collision with hive table
assertThatThrownBy(() -> catalog.createTable(identifier, SCHEMA, PartitionSpec.unpartitioned()))
.isInstanceOf(NoSuchIcebergTableException.class)
.hasMessageStartingWith(String.format("Not an iceberg table: hive.%s", identifier));
Expand All @@ -386,6 +386,12 @@ public void testHiveTableAndIcebergTableWithSameName(TableType tableType)

assertThat(catalog.tableExists(TABLE_IDENTIFIER)).isTrue();
HIVE_METASTORE_EXTENSION.metastoreClient().dropTable(DB_NAME, hiveTableName);

dramaticlly marked this conversation as resolved.
Show resolved Hide resolved
// create an iceberg table after hive table dropped
catalog.createTable(identifier, SCHEMA, PartitionSpec.unpartitioned());
assertThat(catalog.tableExists(identifier)).isTrue();
catalog.dropTable(identifier, true);
assertThat(catalog.tableExists(identifier)).isFalse();
}
dramaticlly marked this conversation as resolved.
Show resolved Hide resolved

private org.apache.hadoop.hive.metastore.api.Table createHiveTable(
Expand Down