Search in sources :

Example 1 with AggregateAnalysis

use of io.confluent.ksql.analyzer.AggregateAnalysis in project ksql by confluentinc.

the class LogicalPlanBuilder method buildLogicalPlan.

public PlanNode buildLogicalPlan(String queryStr) {
    List<Statement> statements = parser.buildAst(queryStr, metaStore);
    Analysis analysis = new Analysis();
    Analyzer analyzer = new Analyzer(queryStr, analysis, metaStore);
    analyzer.process(statements.get(0), new AnalysisContext(null));
    AggregateAnalysis aggregateAnalysis = new AggregateAnalysis();
    AggregateAnalyzer aggregateAnalyzer = new AggregateAnalyzer(aggregateAnalysis, analysis, functionRegistry);
    AggregateExpressionRewriter aggregateExpressionRewriter = new AggregateExpressionRewriter(functionRegistry);
    for (Expression expression : analysis.getSelectExpressions()) {
        aggregateAnalyzer.process(expression, new AnalysisContext(null));
        if (!aggregateAnalyzer.isHasAggregateFunction()) {
            aggregateAnalysis.addNonAggResultColumns(expression);
        }
        aggregateAnalysis.addFinalSelectExpression(ExpressionTreeRewriter.rewriteWith(aggregateExpressionRewriter, expression));
        aggregateAnalyzer.setHasAggregateFunction(false);
    }
    // Build a logical plan
    return new LogicalPlanner(analysis, aggregateAnalysis, functionRegistry).buildPlan();
}
Also used : LogicalPlanner(io.confluent.ksql.planner.LogicalPlanner) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Expression(io.confluent.ksql.parser.tree.Expression) Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) AggregateExpressionRewriter(io.confluent.ksql.util.AggregateExpressionRewriter) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 2 with AggregateAnalysis

use of io.confluent.ksql.analyzer.AggregateAnalysis in project ksql by confluentinc.

the class SqlPredicateTest method buildLogicalPlan.

private PlanNode buildLogicalPlan(String queryStr) {
    List<Statement> statements = KSQL_PARSER.buildAst(queryStr, metaStore);
    // Analyze the query to resolve the references and extract oeprations
    Analysis analysis = new Analysis();
    Analyzer analyzer = new Analyzer("sqlExpression", analysis, metaStore);
    analyzer.process(statements.get(0), new AnalysisContext(null));
    AggregateAnalysis aggregateAnalysis = new AggregateAnalysis();
    AggregateAnalyzer aggregateAnalyzer = new AggregateAnalyzer(aggregateAnalysis, analysis, functionRegistry);
    for (Expression expression : analysis.getSelectExpressions()) {
        aggregateAnalyzer.process(expression, new AnalysisContext(null));
    }
    // Build a logical plan
    PlanNode logicalPlan = new LogicalPlanner(analysis, aggregateAnalysis, functionRegistry).buildPlan();
    return logicalPlan;
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) LogicalPlanner(io.confluent.ksql.planner.LogicalPlanner) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Expression(io.confluent.ksql.parser.tree.Expression) Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 3 with AggregateAnalysis

use of io.confluent.ksql.analyzer.AggregateAnalysis in project ksql by confluentinc.

the class LogicalPlannerTest method buildLogicalPlan.

private PlanNode buildLogicalPlan(String queryStr) {
    List<Statement> statements = KSQL_PARSER.buildAst(queryStr, metaStore);
    // Analyze the query to resolve the references and extract oeprations
    Analysis analysis = new Analysis();
    Analyzer analyzer = new Analyzer("sqlExpression", analysis, metaStore);
    analyzer.process(statements.get(0), new AnalysisContext(null));
    AggregateAnalysis aggregateAnalysis = new AggregateAnalysis();
    AggregateAnalyzer aggregateAnalyzer = new AggregateAnalyzer(aggregateAnalysis, analysis, functionRegistry);
    for (Expression expression : analysis.getSelectExpressions()) {
        aggregateAnalyzer.process(expression, new AnalysisContext(null));
    }
    // Build a logical plan
    PlanNode logicalPlan = new LogicalPlanner(analysis, aggregateAnalysis, functionRegistry).buildPlan();
    return logicalPlan;
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Expression(io.confluent.ksql.parser.tree.Expression) Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 4 with AggregateAnalysis

use of io.confluent.ksql.analyzer.AggregateAnalysis in project ksql by confluentinc.

the class QueryEngine method buildQueryLogicalPlan.

private PlanNode buildQueryLogicalPlan(String sqlExpression, final Query query, final MetaStore tempMetaStore) {
    final QueryAnalyzer queryAnalyzer = new QueryAnalyzer(tempMetaStore, ksqlEngine.getFunctionRegistry());
    final Analysis analysis = queryAnalyzer.analyze(sqlExpression, query);
    final AggregateAnalysis aggAnalysis = queryAnalyzer.analyzeAggregate(query, analysis);
    final PlanNode logicalPlan = new LogicalPlanner(analysis, aggAnalysis, ksqlEngine.getFunctionRegistry()).buildPlan();
    if (logicalPlan instanceof KsqlStructuredDataOutputNode) {
        KsqlStructuredDataOutputNode ksqlStructuredDataOutputNode = (KsqlStructuredDataOutputNode) logicalPlan;
        StructuredDataSource structuredDataSource = new KsqlStream(sqlExpression, ksqlStructuredDataOutputNode.getId().toString(), ksqlStructuredDataOutputNode.getSchema(), ksqlStructuredDataOutputNode.getKeyField(), ksqlStructuredDataOutputNode.getTimestampField() == null ? ksqlStructuredDataOutputNode.getTheSourceNode().getTimestampField() : ksqlStructuredDataOutputNode.getTimestampField(), ksqlStructuredDataOutputNode.getKsqlTopic());
        tempMetaStore.putTopic(ksqlStructuredDataOutputNode.getKsqlTopic());
        tempMetaStore.putSource(structuredDataSource.cloneWithTimeKeyColumns());
    }
    return logicalPlan;
}
Also used : StructuredDataSource(io.confluent.ksql.metastore.StructuredDataSource) KsqlStream(io.confluent.ksql.metastore.KsqlStream) PlanNode(io.confluent.ksql.planner.plan.PlanNode) LogicalPlanner(io.confluent.ksql.planner.LogicalPlanner) Analysis(io.confluent.ksql.analyzer.Analysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) QueryAnalyzer(io.confluent.ksql.analyzer.QueryAnalyzer) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) KsqlStructuredDataOutputNode(io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)

Aggregations

AggregateAnalysis (io.confluent.ksql.analyzer.AggregateAnalysis)4 Analysis (io.confluent.ksql.analyzer.Analysis)4 AggregateAnalyzer (io.confluent.ksql.analyzer.AggregateAnalyzer)3 AnalysisContext (io.confluent.ksql.analyzer.AnalysisContext)3 Analyzer (io.confluent.ksql.analyzer.Analyzer)3 Expression (io.confluent.ksql.parser.tree.Expression)3 Statement (io.confluent.ksql.parser.tree.Statement)3 LogicalPlanner (io.confluent.ksql.planner.LogicalPlanner)3 PlanNode (io.confluent.ksql.planner.plan.PlanNode)3 QueryAnalyzer (io.confluent.ksql.analyzer.QueryAnalyzer)1 KsqlStream (io.confluent.ksql.metastore.KsqlStream)1 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)1 KsqlStructuredDataOutputNode (io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)1 AggregateExpressionRewriter (io.confluent.ksql.util.AggregateExpressionRewriter)1