Skip to content

Commit

Permalink
[hive] Batch list tables and skip checking table exists in filesystem…
Browse files Browse the repository at this point in the history
… with hive catalog (apache#4737)
  • Loading branch information
Zouxxyy authored Dec 19, 2024
1 parent 2db0281 commit 04d7527
Showing 1 changed file with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,17 +437,13 @@ protected void alterDatabaseImpl(String name, List<PropertyChange> changes) {
@Override
protected List<String> listTablesImpl(String databaseName) {
try {
List<String> allTables = clients.run(client -> client.getAllTables(databaseName));
List<String> result = new ArrayList<>(allTables.size());
for (String t : allTables) {
try {
Identifier identifier = new Identifier(databaseName, t);
Table table = getHmsTable(identifier);
if (isPaimonTable(identifier, table)
|| (!formatTableDisabled() && isFormatTable(table))) {
result.add(t);
}
} catch (TableNotExistException ignored) {
List<String> tableNames = clients.run(client -> client.getAllTables(databaseName));
List<Table> hmsTables =
clients.run(client -> client.getTableObjectsByName(databaseName, tableNames));
List<String> result = new ArrayList<>(hmsTables.size());
for (Table table : hmsTables) {
if (isPaimonTable(table) || (!formatTableDisabled() && isFormatTable(table))) {
result.add(table.getTableName());
}
}
return result;
Expand Down Expand Up @@ -479,7 +475,7 @@ public TableSchema getDataTableSchema(Identifier identifier) throws TableNotExis

private TableSchema getDataTableSchema(Identifier identifier, Table table)
throws TableNotExistException {
if (!isPaimonTable(identifier, table)) {
if (!isPaimonTable(table)) {
throw new TableNotExistException(identifier);
}

Expand Down Expand Up @@ -876,7 +872,7 @@ private Table renameHiveTable(Identifier fromTable, Identifier toTable) {
protected void alterTableImpl(Identifier identifier, List<SchemaChange> changes)
throws TableNotExistException, ColumnAlreadyExistException, ColumnNotExistException {
Table table = getHmsTable(identifier);
if (!isPaimonTable(identifier, table)) {
if (!isPaimonTable(table)) {
throw new UnsupportedOperationException("Only data table support alter table.");
}

Expand Down Expand Up @@ -1050,12 +1046,6 @@ public Table getHmsTable(Identifier identifier) throws TableNotExistException {
}
}

private boolean isPaimonTable(Identifier identifier, Table table) {
return isPaimonTable(table)
&& tableExistsInFileSystem(
getTableLocation(identifier, table), identifier.getBranchNameOrDefault());
}

private static boolean isPaimonTable(Table table) {
boolean isPaimonTable =
INPUT_FORMAT_CLASS_NAME.equals(table.getSd().getInputFormat())
Expand Down

0 comments on commit 04d7527

Please sign in to comment.