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 56aa3d4 commit 342c290
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public Operation convertToOperation(HiveParserASTNode ast) throws SemanticExcept
res = convertDescribeTable(ast);
break;
case HiveASTParser.TOK_SHOWDATABASES:
res = convertShowDatabases();
res = convertShowDatabases(catalogRegistry.getCurrentCatalog());
break;
case HiveASTParser.TOK_SHOWTABLES:
res = convertShowTables(ast, false);
Expand Down Expand Up @@ -1803,8 +1803,8 @@ private Operation convertShowPartitions(HiveParserASTNode ast) throws SemanticEx
HiveConf.getVar(conf, HiveConf.ConfVars.DEFAULTPARTITIONNAME));
}

private Operation convertShowDatabases() {
return new ShowDatabasesOperation();
private Operation convertShowDatabases(String catalogName) {
return new ShowDatabasesOperation(catalogName);
}

private Operation convertShowTables(HiveParserASTNode ast, boolean expectView) {
Expand Down Expand Up @@ -1843,7 +1843,11 @@ private Operation convertShowTables(HiveParserASTNode ast, boolean expectView) {
if (pattern != null) {
handleUnsupportedOperation("SHOW TABLES/VIEWS LIKE is not supported");
}
return expectView ? new ShowViewsOperation() : new ShowTablesOperation();
return expectView
? new ShowViewsOperation(
catalogRegistry.getCurrentCatalog(), catalogRegistry.getCurrentDatabase())
: new ShowTablesOperation(
catalogRegistry.getCurrentCatalog(), catalogRegistry.getCurrentDatabase());
}

/**
Expand All @@ -1857,7 +1861,8 @@ private Operation convertShowFunctions(HiveParserASTNode ast) {
assert (ast.getChild(0).getType() == HiveASTParser.KW_LIKE);
throw new ValidationException("SHOW FUNCTIONS LIKE is not supported yet");
}
return new ShowFunctionsOperation();
return new ShowFunctionsOperation(
catalogRegistry.getCurrentCatalog(), catalogRegistry.getCurrentDatabase());
}

private Operation convertAlterTableRename(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
*/
@Internal
public abstract class AbstractShowOperation implements ShowOperation {
protected final @Nullable String catalogName;
protected final String catalogName;
protected final @Nullable String preposition;
protected final @Nullable ShowLikeOperator likeOp;

public AbstractShowOperation(
@Nullable String catalogName,
@Nullable String preposition,
@Nullable ShowLikeOperator likeOp) {
String catalogName, @Nullable String preposition, @Nullable ShowLikeOperator likeOp) {
this.catalogName = catalogName;
this.preposition = preposition;
this.likeOp = likeOp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,21 @@
public class ShowDatabasesOperation extends AbstractShowOperation {

public ShowDatabasesOperation(
@Nullable String catalogName,
@Nullable String preposition,
@Nullable ShowLikeOperator likeOp) {
String catalogName, @Nullable String preposition, @Nullable ShowLikeOperator likeOp) {
super(catalogName, preposition, likeOp);
}

public ShowDatabasesOperation(ShowLikeOperator likeOp) {
this(null, null, likeOp);
public ShowDatabasesOperation(String catalogName, ShowLikeOperator likeOp) {
this(catalogName, null, likeOp);
}

public ShowDatabasesOperation() {
this(null, null, null);
public ShowDatabasesOperation(String catalogName) {
this(catalogName, null, null);
}

@Override
protected Collection<String> retrieveDataForTableResult(Context ctx) {
final CatalogManager catalogManager = ctx.getCatalogManager();
final String catalogName = catalogManager.qualifyCatalog(this.catalogName);
return catalogManager.getCatalogOrThrowException(catalogName).listDatabases();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,26 @@ public enum FunctionScope {
}

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

public ShowFunctionsOperation() {
public ShowFunctionsOperation(String catalogName, String databaseName) {
// "SHOW FUNCTIONS" default is ALL scope
this(FunctionScope.ALL, null);
this(FunctionScope.ALL, catalogName, databaseName, null);
}

public ShowFunctionsOperation(FunctionScope functionScope, @Nullable ShowLikeOperator likeOp) {
this(functionScope, null, null, null, likeOp);
public ShowFunctionsOperation(
FunctionScope functionScope,
String catalogName,
String databaseName,
@Nullable ShowLikeOperator likeOp) {
this(functionScope, null, catalogName, databaseName, likeOp);
}

public ShowFunctionsOperation(
FunctionScope functionScope,
@Nullable String preposition,
@Nullable String catalogName,
@Nullable String databaseName,
String catalogName,
String databaseName,
@Nullable ShowLikeOperator likeOp) {
super(catalogName, preposition, likeOp);
this.functionScope = functionScope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,44 +41,38 @@
@Internal
public class ShowProceduresOperation extends AbstractShowOperation {

private final @Nullable String databaseName;
private final String databaseName;

public ShowProceduresOperation(
@Nullable String catalogName,
@Nullable String databaseName,
String catalogName,
String databaseName,
@Nullable String preposition,
@Nullable ShowLikeOperator likeOp) {
super(catalogName, preposition, likeOp);
this.databaseName = databaseName;
}

public ShowProceduresOperation(@Nullable ShowLikeOperator likeOp) {
this(null, null, null, likeOp);
public ShowProceduresOperation(
String catalogName, String databaseName, @Nullable ShowLikeOperator likeOp) {
this(catalogName, databaseName, null, likeOp);
}

@Override
protected Collection<String> retrieveDataForTableResult(Context ctx) {
final CatalogManager catalogManager = ctx.getCatalogManager();
final String catalogName = catalogManager.qualifyCatalog(this.catalogName);
final String dbName = catalogManager.qualifyDatabase(this.databaseName);
try {
if (preposition == null) {
// it's to show current_catalog.current_database
return catalogManager
.getCatalogOrError(catalogManager.getCurrentCatalog())
.listProcedures(catalogManager.getCurrentDatabase());
return catalogManager.getCatalogOrError(catalogName).listProcedures(databaseName);
} else {
Catalog catalog = catalogManager.getCatalogOrThrowException(catalogName);
return catalog.listProcedures(dbName);
return catalog.listProcedures(databaseName);
}
} catch (DatabaseNotExistException e) {
throw new TableException(
String.format(
"Fail to show procedures because the Database `%s` to show from/in does not exist in Catalog `%s`.",
preposition == null ? catalogManager.getCurrentDatabase() : dbName,
preposition == null
? catalogManager.getCurrentCatalog()
: catalogName));
databaseName, catalogName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,39 @@
@Internal
public class ShowTablesOperation extends AbstractShowOperation {

private final @Nullable String databaseName;
private final String databaseName;

public ShowTablesOperation(
@Nullable String catalogName,
@Nullable String databaseName,
String catalogName,
String databaseName,
@Nullable String preposition,
@Nullable ShowLikeOperator likeOp) {
super(catalogName, preposition, likeOp);
this.databaseName = databaseName;
}

public ShowTablesOperation(@Nullable ShowLikeOperator likeOp) {
this(null, null, null, likeOp);
public ShowTablesOperation(
String catalogName, String databaseName, @Nullable ShowLikeOperator likeOp) {
this(catalogName, databaseName, null, likeOp);
}

public ShowTablesOperation() {
this(null);
public ShowTablesOperation(String catalogName, String databaseName) {
this(catalogName, databaseName, null);
}

@Override
protected Set<String> retrieveDataForTableResult(Context ctx) {
final CatalogManager catalogManager = ctx.getCatalogManager();
final String catalogName = catalogManager.qualifyCatalog(this.catalogName);
final String dbName = catalogManager.qualifyDatabase(this.databaseName);
if (preposition == null) {
return catalogManager.listTables();
} else {
Catalog catalog = catalogManager.getCatalogOrThrowException(catalogName);
if (catalog.databaseExists(dbName)) {
return catalogManager.listTables(catalogName, dbName);
if (catalog.databaseExists(databaseName)) {
return catalogManager.listTables(catalogName, databaseName);
} else {
throw new ValidationException(
String.format("Database '%s'.'%s' doesn't exist.", catalogName, dbName));
String.format(
"Database '%s'.'%s' doesn't exist.", catalogName, databaseName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,24 @@
@Internal
public class ShowViewsOperation extends AbstractShowOperation {

private final @Nullable String databaseName;
private final String databaseName;

public ShowViewsOperation(
@Nullable String catalogName,
@Nullable String databaseName,
String catalogName,
String databaseName,
@Nullable String preposition,
@Nullable ShowLikeOperator likeOp) {
super(catalogName, preposition, likeOp);
this.databaseName = databaseName;
}

public ShowViewsOperation(@Nullable ShowLikeOperator likeOp) {
this(null, null, null, likeOp);
public ShowViewsOperation(
String catalogName, String databaseName, @Nullable ShowLikeOperator likeOp) {
this(catalogName, databaseName, null, likeOp);
}

public ShowViewsOperation() {
this(null);
public ShowViewsOperation(String catalogName, String databaseName) {
this(catalogName, databaseName, null);
}

@Override
Expand All @@ -65,17 +66,16 @@ protected String getOperationName() {

protected Set<String> retrieveDataForTableResult(Context ctx) {
final CatalogManager catalogManager = ctx.getCatalogManager();
final String catalogName = catalogManager.qualifyCatalog(this.catalogName);
final String dbName = catalogManager.qualifyDatabase(this.databaseName);
if (preposition == null) {
return catalogManager.listViews();
} else {
Catalog catalog = catalogManager.getCatalogOrThrowException(catalogName);
if (catalog.databaseExists(dbName)) {
return catalogManager.listViews(catalogName, dbName);
if (catalog.databaseExists(databaseName)) {
return catalogManager.listViews(catalogName, databaseName);
} else {
throw new ValidationException(
String.format("Database '%s'.'%s' doesn't exist.", catalogName, dbName));
String.format(
"Database '%s'.'%s' doesn't exist.", catalogName, databaseName));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public abstract class AbstractSqlShowConverter<T extends SqlShowCall>
protected Operation convertShowOperation(T sqlShowCall, ConvertContext context) {
final ShowLikeOperator likeOp = getLikeOp(sqlShowCall);
if (sqlShowCall.getPreposition() == null) {
return getOperationWithoutPrep(sqlShowCall, likeOp);
final CatalogManager catalogManager = context.getCatalogManager();
final String catalogName =
catalogManager.qualifyCatalog(catalogManager.getCurrentCatalog());
final String databaseName =
catalogManager.qualifyDatabase(catalogManager.getCurrentDatabase());
return getOperationWithoutPrep(catalogName, databaseName, sqlShowCall, likeOp);
}
List<String> sqlIdentifierNameList = sqlShowCall.getSqlIdentifierNameList();
if (sqlIdentifierNameList.size() > 2) {
Expand Down Expand Up @@ -65,12 +70,16 @@ public ShowLikeOperator getLikeOp(SqlShowCall sqlShowCall) {
sqlShowCall.getLikeSqlPattern());
}

public abstract Operation getOperationWithoutPrep(T sqlShowCall, ShowLikeOperator likeOp);
public abstract Operation getOperationWithoutPrep(
String catalogName,
String databaseName,
T sqlShowCall,
@Nullable ShowLikeOperator likeOp);

public abstract Operation getOperation(
T sqlShowCall,
@Nullable String catalogName,
@Nullable String databaseName,
String catalogName,
String databaseName,
@Nullable String prep,
@Nullable ShowLikeOperator likeOp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.flink.table.planner.operations.converters;

import org.apache.flink.sql.parser.dql.SqlShowDatabases;
import org.apache.flink.table.catalog.CatalogManager;
import org.apache.flink.table.operations.Operation;
import org.apache.flink.table.operations.ShowDatabasesOperation;
import org.apache.flink.table.operations.utils.LikeType;
Expand All @@ -34,7 +35,10 @@ public Operation convertSqlNode(SqlShowDatabases sqlShowDatabases, ConvertContex
LikeType.of(sqlShowDatabases.getLikeType(), sqlShowDatabases.isNotLike()),
sqlShowDatabases.getLikeSqlPattern());
if (sqlShowDatabases.getPreposition() == null) {
return new ShowDatabasesOperation(likeOp);
final CatalogManager catalogManager = context.getCatalogManager();
final String currentCatalogName = catalogManager.getCurrentCatalog();
final String qualifiedCatalogName = catalogManager.qualifyCatalog(currentCatalogName);
return new ShowDatabasesOperation(qualifiedCatalogName, likeOp);
} else {
return new ShowDatabasesOperation(
sqlShowDatabases.getCatalogName(), sqlShowDatabases.getPreposition(), likeOp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ public class SqlShowFunctionsConverter extends AbstractSqlShowConverter<SqlShowF

@Override
public Operation getOperationWithoutPrep(
SqlShowFunctions sqlShowFunctions, ShowLikeOperator likeOp) {
String qualifiedCatalogName,
String qualifiedDatabaseName,
SqlShowFunctions sqlShowFunctions,
ShowLikeOperator likeOp) {
final FunctionScope functionScope = getFunctionScope(sqlShowFunctions);
return new ShowFunctionsOperation(functionScope, likeOp);
return new ShowFunctionsOperation(
functionScope, qualifiedCatalogName, qualifiedDatabaseName, likeOp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public class SqlShowProcedureConverter extends AbstractSqlShowConverter<SqlShowP

@Override
public Operation getOperationWithoutPrep(
SqlShowProcedures sqlShowCall, ShowLikeOperator likeOp) {
return new ShowProceduresOperation(likeOp);
String qualifiedCatalogName,
String qualifiedDatabaseName,
SqlShowProcedures sqlShowCall,
ShowLikeOperator likeOp) {
return new ShowProceduresOperation(qualifiedCatalogName, qualifiedDatabaseName, likeOp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

public class SqlShowTablesConverter extends AbstractSqlShowConverter<SqlShowTables> {
@Override
public Operation getOperationWithoutPrep(SqlShowTables sqlShowCall, ShowLikeOperator likeOp) {
return new ShowTablesOperation(likeOp);
public Operation getOperationWithoutPrep(
String qualifiedCatalogName,
String qualifiedDatabaseName,
SqlShowTables sqlShowCall,
ShowLikeOperator likeOp) {
return new ShowTablesOperation(qualifiedCatalogName, qualifiedDatabaseName, likeOp);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@

public class SqlShowViewsConverter extends AbstractSqlShowConverter<SqlShowViews> {
@Override
public Operation getOperationWithoutPrep(SqlShowViews sqlShowCall, ShowLikeOperator likeOp) {
return new ShowViewsOperation(likeOp);
public Operation getOperationWithoutPrep(
String qualifiedCatalogName,
String qualifiedDatabaseName,
SqlShowViews sqlShowCall,
ShowLikeOperator likeOp) {
return new ShowViewsOperation(qualifiedCatalogName, qualifiedDatabaseName, likeOp);
}

@Override
Expand Down

0 comments on commit 342c290

Please sign in to comment.