THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
show | Support or Not | Support filter or Not |
show tables | Yes | Yes |
show columns | Yes | Yes |
show catalogs | Yes | No |
show databases | Yes | No |
show functions | Yes | No |
show views | Yes | No |
show modules | Yes | No |
show jars | Yes | No |
show jobs | Yes | No |
show connectors | No | No |
We can see current flink many sql statements only support showing with full datas, without 'FROM/IN' or 'LIKE' filter clause.
...
In TableEnvironmentImpl we do filter for returned full results.
Some SqlNodes and Operations could be added or changed.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// Add SqlDescribeCatalog & DescribeCatalogOperation // Add SqlDescribeDatabase & DescribeDatabaseOperation // Add SqlDescribeFunction & DescribeFunctionOperation // Changed Operations(offerSqlNodes filtering& support)Operations // ShowCatalogsOperationSqlShowCatalogs public class ShowCatalogsOperationSqlShowCatalogs implementsextends ShowOperationSqlCall { public static //final hasSqlSpecialOperator likeOPERATOR sub-clause= private final boolean withLike new SqlSpecialOperator("SHOW CATALOGS", SqlKind.OTHER); // trueAdd for not like, false is likeLIKE support privateprotected final boolean notLike; // like or not like pattern (sql-like-pattern, consistent with current flink behavior)protected final SqlCharStringLiteral likeLiteral; public SqlShowCatalogs(SqlParserPos pos) { private final String likePattern; public ShowCatalogsOperation(boolean withLike, boolean notLike, String likePattern) { super(pos); this.withLikenotLike = withLikefalse; this.notLikelikeLiteral = notLikenull; } this.likePattern = likePattern; } } // ShowDatabasesOperation public class ShowDatabasesOperation implements ShowOperation { private final String catalogName; private final boolean withLikepublic SqlShowCatalogs(SqlParserPos pos, boolean notLike, SqlCharStringLiteral likeLiteral) { super(pos); this.notLike = notLike; private final boolean notLike; this.likeLiteral = likeLiteral; private final String likePattern;} //public inboolean or from to indicate specific catalog or database private final String preposition;isNotLike() { return notLike; } public String ShowDatabasesOperationgetLikeSqlPattern() { String catalogName, return Objects.isNull(this.likeLiteral) ? null : likeLiteral.getValueAs(String.class); } public boolean boolean withLike,isWithLike() { return Objects.nonNull(likeLiteral); boolean notLike,} @Override public SqlOperator getOperator() { String likePattern, return OPERATOR; } String preposition) {@Override public List<SqlNode> getOperandList() { this.catalogName = catalogName; return this.withLike = withLikeCollections.emptyList(); } this.notLike = notLike;@Override public void unparse(SqlWriter this.likePattern = likePattern;writer, int leftPrec, int rightPrec) { this.preposition = prepositionwriter.keyword("SHOW CATALOGS"); } } // ShowFunctionsOperation public class ShowFunctionsOperation implements ShowOperationif (isWithLike()) { private final String catalogName; private final String databaseName;if (isNotLike()) { private final boolean withLike; private final boolean notLike; writer.keyword(String.format("NOT LIKE private final String likePattern'%s'", getLikeSqlPattern())); private final String preposition; private final} FunctionScopeelse functionScope; { /** * Represent scope of function. writer.keyword(String.format("LIKE *'%s'", getLikeSqlPattern())); * <ul> * } <li><b>USER</b> return only user-defined functions } * <li><b>ALL</b> return all user-defined and built-in functions} } // ShowCatalogsOperation public class ShowCatalogsOperation implements ShowOperation { private * </ul>final boolean withLike; */private final boolean notLike; publicprivate enumfinal FunctionScopeString {likePattern; USER,public ShowCatalogsOperation(boolean notLike, String likePattern) { ALL this.withLike = likePattern != } null; public ShowFunctionsOperation( this.notLike = notLike; String catalogName, this.likePattern = likePattern; } public boolean String databaseName,isWithLike() { return withLike; boolean withLike,} public boolean isNotLike() { boolean notLike, return notLike; } public String likePattern,getLikePattern() { return likePattern; String preposition,} @Override public FunctionScope functionScopeString asSummaryString() { this.catalogNameStringBuilder builder = catalogName new StringBuilder().append("SHOW CATALOGS"); this.databaseName = databaseName;if (withLike) { this.withLike = withLike; this.notLike = notLike;if (notLike) { this.likePattern = likePattern; this.preposition = prepositionbuilder.append(String.format(" %s LIKE %s", "NOT", likePattern)); this.functionScope = functionScope; } else }{ public FunctionScope getFunctionScope() { return functionScope; } } // ShowViewsOperation public class ShowViewsOperation implements ShowOperation { builder.append(String.format(" LIKE %s", likePattern)); private final String} catalogName; private final String databaseName;} private final boolean withLikereturn builder.toString(); private final boolean notLike; private final String likePattern; private final String preposition; } } // SqlShowDatabases public class SqlShowDatabases extends SqlCall { public static final SqlSpecialOperator OPERATOR = public ShowViewsOperation( new SqlSpecialOperator("SHOW String catalogName,DATABASES", SqlKind.OTHER); // Add IN/FROM and LIKE support protected String databaseName,final SqlIdentifier catalogName; protected final String preposition; protected final boolean withLike,notLike; protected final SqlCharStringLiteral likeLiteral; boolean notLike,public SqlShowDatabases(SqlParserPos pos) { super(pos); String likePattern, this.catalogName = null; String this.preposition) = {null; this.catalogNamenotLike = catalogNamefalse; this.databaseNamelikeLiteral = databaseNamenull; } this.withLike = withLike;public SqlShowDatabases( this.notLike = notLike; SqlParserPos pos, this.likePattern = likePattern; SqlIdentifier catalogName, this.preposition = preposition; } } // ShowModulesOperation public class ShowModulesOperation implements ShowOperationString {preposition, private final boolean requireFull; private final boolean withLike;notLike, private final boolean notLike; private finalSqlCharStringLiteral StringlikeLiteral) likePattern;{ public ShowModulesOperation( super(pos); this.preposition = preposition; boolean requireFull, boolean withLike, boolean notLike, String likePattern) {this.catalogName = this.requireFull = requireFull; preposition this.withLike != withLike;null this.notLike = notLike; this.likePattern = likePattern; } public boolean requireFull() {? requireNonNull(catalogName, "Catalog name must not be null.") return requireFull; } } // ShowJarsOperation public class ShowJarsOperation implements ShowOperation { private final: boolean withLikenull; private final boolean this.notLike = notLike; private final String likePattern; this.likeLiteral = likeLiteral; public ShowJarsOperation(boolean withLike, boolean notLike, String likePattern} public SqlIdentifier getCatalogName() { this.withLike = withLikereturn catalogName; } this.notLikepublic = notLike; String catalogName() { return this.likePattern = likePatterncatalogName != null ? catalogName.getSimple() : null; } } // ShowJobsOperation public class ShowJobsOperation implements ShowOperation public String getPreposition() { private final booleanreturn withLikepreposition; } private final boolean notLike; public boolean isWithLike() { private final String likePatternreturn Objects.nonNull(likeLiteral); public ShowJobsOperation(boolean withLike, boolean notLike, String likePattern} public boolean isNotLike() { this.withLike = withLikereturn notLike; } this.notLikepublic = notLike;SqlCharStringLiteral getLikeLiteral() { this.likePattern = likePatternreturn likeLiteral; } public String getLikeSqlPattern() { return Objects.isNull(this.likeLiteral) ? null : likeLiteral.getValueAs(String.class); } @Override public SqlOperator getOperator() { return OPERATOR; } @Override public List<SqlNode> getOperandList() { return Objects.isNull(this.catalogName) ? Collections.emptyList() : Collections.singletonList(catalogName); } @Override public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { if (this.preposition == null) { writer.keyword("SHOW DATABASES"); } else if (catalogName != null) { writer.keyword("SHOW DATABASES " + this.preposition); catalogName.unparse(writer, leftPrec, rightPrec); } if (isWithLike()) { if (isNotLike()) { writer.keyword(String.format("NOT LIKE '%s'", getLikeSqlPattern())); } else { writer.keyword(String.format("LIKE '%s'", getLikeSqlPattern())); } } } } // ShowDatabasesOperation public class ShowDatabasesOperation implements ShowOperation { private final String preposition; private final String catalogName; private final boolean withLike; private final boolean notLike; private final String likePattern; public ShowDatabasesOperation() { this.preposition = null; this.catalogName = null; this.withLike = false; this.notLike = false; this.likePattern = null; } public ShowDatabasesOperation(boolean notLike, String likePattern) { this.preposition = null; this.catalogName = null; this.withLike = likePattern != null; this.notLike = notLike; this.likePattern = likePattern; } public ShowDatabasesOperation( String preposition, String catalogName, boolean notLike, String likePattern) { this.preposition = checkNotNull(preposition, "Preposition must not be null"); this.catalogName = checkNotNull(catalogName, "Catalog name must not be null"); this.withLike = likePattern != null; this.notLike = notLike; this.likePattern = likePattern; } public String getPreposition() { return preposition; } public String getCatalogName() { return catalogName; } public boolean isWithLike() { return withLike; } public boolean isNotLike() { return notLike; } public String getLikePattern() { return likePattern; } @Override public String asSummaryString() { StringBuilder builder = new StringBuilder().append("SHOW DATABASES"); if (preposition != null) { builder.append(String.format(" %s %s", preposition, catalogName)); } if (withLike) { if (notLike) { builder.append(String.format(" %s LIKE %s", "NOT", likePattern)); } else { builder.append(String.format(" LIKE %s", likePattern)); } } return builder.toString(); } } // omit here. basically same as ShowCatalogs/ShowDatabases above. // SqlShowFunctions & ShowFunctionsOperation // SqlShowViews & ShowViewsOperation // SqlShowModules & ShowModulesOperation // SqlShowJars & ShowJarsOperation // SqlShowJobs & ShowJobsOperation // SqlShowConnectors & ShowConnectorsOperation |
Future Work
to be added
Compatibility, Deprecation, and Migration Plan
...