Skip to content

Commit

Permalink
[hive] Refactor HiveCatalog to reduce io when getTable (#4409)
Browse files Browse the repository at this point in the history
  • Loading branch information
JingsongLi authored Oct 31, 2024
1 parent e2acdc2 commit 937732b
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -355,37 +355,38 @@ public Table getTable(Identifier identifier) throws TableNotExistException {
}
return table;
} else if (isSpecifiedSystemTable(identifier)) {
FileStoreTable originTable =
getDataTable(
Table originTable =
getDataOrFormatTable(
new Identifier(
identifier.getDatabaseName(),
identifier.getTableName(),
identifier.getBranchName(),
null));
if (!(originTable instanceof FileStoreTable)) {
throw new UnsupportedOperationException(
String.format(
"Only data table support system tables, but this table %s is %s.",
identifier, originTable.getClass()));
}
Table table =
SystemTableLoader.load(
Preconditions.checkNotNull(identifier.getSystemTableName()),
originTable);
(FileStoreTable) originTable);
if (table == null) {
throw new TableNotExistException(identifier);
}
return table;
} else {
try {
return getDataTable(identifier);
} catch (TableNotExistException e) {
return getFormatTable(identifier);
}
return getDataOrFormatTable(identifier);
}
}

private FileStoreTable getDataTable(Identifier identifier) throws TableNotExistException {
protected Table getDataOrFormatTable(Identifier identifier) throws TableNotExistException {
Preconditions.checkArgument(identifier.getSystemTableName() == null);
TableSchema tableSchema = getDataTableSchema(identifier);
return FileStoreTableFactory.create(
fileIO,
getTableLocation(identifier),
tableSchema,
getDataTableSchema(identifier),
new CatalogEnvironment(
identifier,
Lock.factory(
Expand All @@ -394,17 +395,6 @@ private FileStoreTable getDataTable(Identifier identifier) throws TableNotExistE
lineageMetaFactory));
}

/**
* Return a {@link FormatTable} identified by the given {@link Identifier}.
*
* @param identifier Path of the table
* @return The requested table
* @throws Catalog.TableNotExistException if the target does not exist
*/
public FormatTable getFormatTable(Identifier identifier) throws Catalog.TableNotExistException {
throw new Catalog.TableNotExistException(identifier);
}

/**
* Create a {@link FormatTable} identified by the given {@link Identifier}.
*
Expand Down Expand Up @@ -473,12 +463,12 @@ public static boolean isSpecifiedSystemTable(Identifier identifier) {
return identifier.getSystemTableName() != null;
}

protected static boolean isSystemTable(Identifier identifier) {
protected static boolean isTableInSystemDatabase(Identifier identifier) {
return isSystemDatabase(identifier.getDatabaseName()) || isSpecifiedSystemTable(identifier);
}

protected static void checkNotSystemTable(Identifier identifier, String method) {
if (isSystemTable(identifier)) {
if (isTableInSystemDatabase(identifier)) {
throw new IllegalArgumentException(
String.format(
"Cannot '%s' for system table '%s', please use data table.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ default Optional<CatalogLockContext> lockContext() {
}

/** Get metastore client factory for the table specified by {@code identifier}. */
default Optional<MetastoreClient.Factory> metastoreClientFactory(Identifier identifier) {
default Optional<MetastoreClient.Factory> metastoreClientFactory(Identifier identifier)
throws TableNotExistException {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ public Optional<CatalogLockContext> lockContext() {
}

@Override
public Optional<MetastoreClient.Factory> metastoreClientFactory(Identifier identifier) {
public Optional<MetastoreClient.Factory> metastoreClientFactory(Identifier identifier)
throws TableNotExistException {
return wrapped.metastoreClientFactory(identifier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected List<String> listTablesImpl(String databaseName) {

@Override
public boolean tableExists(Identifier identifier) {
if (isSystemTable(identifier)) {
if (isTableInSystemDatabase(identifier)) {
return super.tableExists(identifier);
}

Expand Down
Loading

0 comments on commit 937732b

Please sign in to comment.