Search in sources :

Example 1 with SqlAdvisorValidator

use of org.apache.calcite.sql.advise.SqlAdvisorValidator in project flink by apache.

the class ParserImpl method getCompletionHints.

public String[] getCompletionHints(String statement, int cursor) {
    List<String> candidates = new ArrayList<>(Arrays.asList(EXTENDED_PARSER.getCompletionHints(statement, cursor)));
    // use sql advisor
    SqlAdvisorValidator validator = validatorSupplier.get().getSqlAdvisorValidator();
    SqlAdvisor advisor = new SqlAdvisor(validator, validatorSupplier.get().config().getParserConfig());
    String[] replaced = new String[1];
    List<String> sqlHints = advisor.getCompletionHints(statement, cursor, replaced).stream().map(item -> item.toIdentifier().toString()).collect(Collectors.toList());
    candidates.addAll(sqlHints);
    return candidates.toArray(new String[0]);
}
Also used : CatalogManager(org.apache.flink.table.catalog.CatalogManager) Arrays(java.util.Arrays) UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) FlinkPlannerImpl(org.apache.flink.table.planner.calcite.FlinkPlannerImpl) SqlAdvisorValidator(org.apache.calcite.sql.advise.SqlAdvisorValidator) FlinkTypeFactory(org.apache.flink.table.planner.calcite.FlinkTypeFactory) RowType(org.apache.flink.table.types.logical.RowType) Supplier(java.util.function.Supplier) CalciteParser(org.apache.flink.table.planner.parse.CalciteParser) ArrayList(java.util.ArrayList) SqlNode(org.apache.calcite.sql.SqlNode) RexNode(org.apache.calcite.rex.RexNode) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) SqlToOperationConverter(org.apache.flink.table.planner.operations.SqlToOperationConverter) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) ExtendedParser(org.apache.flink.table.planner.parse.ExtendedParser) SqlExprToRexConverter(org.apache.flink.table.planner.calcite.SqlExprToRexConverter) Nullable(javax.annotation.Nullable) Operation(org.apache.flink.table.operations.Operation) TableException(org.apache.flink.table.api.TableException) Parser(org.apache.flink.table.delegation.Parser) Preconditions(org.apache.flink.util.Preconditions) Collectors(java.util.stream.Collectors) SqlExprToRexConverterFactory(org.apache.flink.table.planner.calcite.SqlExprToRexConverterFactory) List(java.util.List) LogicalType(org.apache.flink.table.types.logical.LogicalType) Optional(java.util.Optional) RexNodeExpression(org.apache.flink.table.planner.expressions.RexNodeExpression) TypeConversions(org.apache.flink.table.types.utils.TypeConversions) SqlAdvisor(org.apache.calcite.sql.advise.SqlAdvisor) SqlNodeList(org.apache.calcite.sql.SqlNodeList) Collections(java.util.Collections) ArrayList(java.util.ArrayList) SqlAdvisorValidator(org.apache.calcite.sql.advise.SqlAdvisorValidator) SqlAdvisor(org.apache.calcite.sql.advise.SqlAdvisor)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Supplier (java.util.function.Supplier)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 RexNode (org.apache.calcite.rex.RexNode)1 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)1 SqlNode (org.apache.calcite.sql.SqlNode)1 SqlNodeList (org.apache.calcite.sql.SqlNodeList)1 SqlAdvisor (org.apache.calcite.sql.advise.SqlAdvisor)1 SqlAdvisorValidator (org.apache.calcite.sql.advise.SqlAdvisorValidator)1 TableException (org.apache.flink.table.api.TableException)1 CatalogManager (org.apache.flink.table.catalog.CatalogManager)1 UnresolvedIdentifier (org.apache.flink.table.catalog.UnresolvedIdentifier)1 Parser (org.apache.flink.table.delegation.Parser)1 ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)1 Operation (org.apache.flink.table.operations.Operation)1