Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
snuyanzin committed Aug 19, 2024
1 parent 342c290 commit fac9cfd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public enum FunctionScope {
}

private final FunctionScope functionScope;
private final String databaseName;
private final @Nullable String databaseName;

public ShowFunctionsOperation(String catalogName, String databaseName) {
// "SHOW FUNCTIONS" default is ALL scope
Expand All @@ -64,8 +64,8 @@ public ShowFunctionsOperation(String catalogName, String databaseName) {

public ShowFunctionsOperation(
FunctionScope functionScope,
String catalogName,
String databaseName,
@Nullable String catalogName,
@Nullable String databaseName,
@Nullable ShowLikeOperator likeOp) {
this(functionScope, null, catalogName, databaseName, likeOp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,32 +36,42 @@ protected Operation convertShowOperation(T sqlShowCall, ConvertContext context)
final ShowLikeOperator likeOp = getLikeOp(sqlShowCall);
if (sqlShowCall.getPreposition() == null) {
final CatalogManager catalogManager = context.getCatalogManager();
final String catalogName =
catalogManager.qualifyCatalog(catalogManager.getCurrentCatalog());
final String databaseName =
catalogManager.qualifyDatabase(catalogManager.getCurrentDatabase());
final String currentCatalogName = catalogManager.getCurrentCatalog();
final String currentDatabaseName = catalogManager.getCurrentDatabase();
if (skipQualifyingCatalogAndDatabase()) {
getOperationWithoutPrep(
currentCatalogName, currentDatabaseName, sqlShowCall, likeOp);
}
final String catalogName = catalogManager.qualifyCatalog(currentCatalogName);
final String databaseName = catalogManager.qualifyDatabase(currentDatabaseName);
return getOperationWithoutPrep(catalogName, databaseName, sqlShowCall, likeOp);
}
List<String> sqlIdentifierNameList = sqlShowCall.getSqlIdentifierNameList();
final List<String> sqlIdentifierNameList = sqlShowCall.getSqlIdentifierNameList();
if (sqlIdentifierNameList.size() > 2) {
throw new ValidationException(
String.format(
"%s from/in identifier [ %s ] format error, it should be [catalog_name.]database_name.",
sqlShowCall.getOperator().getName(),
String.join(".", sqlIdentifierNameList)));
}
CatalogManager catalogManager = context.getCatalogManager();
String catalogName =
final CatalogManager catalogManager = context.getCatalogManager();
final String catalogName =
sqlIdentifierNameList.size() == 1
? catalogManager.getCurrentCatalog()
: sqlIdentifierNameList.get(0);

String databaseName =
final String databaseName =
sqlIdentifierNameList.size() == 1
? sqlIdentifierNameList.get(0)
: sqlIdentifierNameList.get(1);
final String qualifiedCatalogName = catalogManager.qualifyCatalog(catalogName);
final String qualifiedDatabaseName = catalogManager.qualifyDatabase(databaseName);
return getOperation(
sqlShowCall, catalogName, databaseName, sqlShowCall.getPreposition(), likeOp);
sqlShowCall,
qualifiedCatalogName,
qualifiedDatabaseName,
sqlShowCall.getPreposition(),
likeOp);
}

public ShowLikeOperator getLikeOp(SqlShowCall sqlShowCall) {
Expand All @@ -85,4 +95,8 @@ public abstract Operation getOperation(

@Override
public abstract Operation convertSqlNode(T node, ConvertContext context);

protected boolean skipQualifyingCatalogAndDatabase() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,11 @@ public Operation convertSqlNode(SqlShowFunctions sqlShowFunctions, ConvertContex
private static FunctionScope getFunctionScope(SqlShowFunctions sqlShowFunctions) {
return sqlShowFunctions.requireUser() ? FunctionScope.USER : FunctionScope.ALL;
}

@Override
protected boolean skipQualifyingCatalogAndDatabase() {
// It should be supported to list functions with unset catalog
// for more info FLINK-33093
return true;
}
}

0 comments on commit fac9cfd

Please sign in to comment.