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] Refactor HiveCatalog to reduce io when getTable #4409

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading