Search in sources :

Example 21 with PlanNode

use of io.confluent.ksql.planner.plan.PlanNode 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 22 with PlanNode

use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.

the class LogicalPlannerTest method testSimpleLeftJoinLogicalPlan.

@Test
public void testSimpleLeftJoinLogicalPlan() throws Exception {
    String simpleQuery = "SELECT t1.col1, t2.col1, t1.col4, t2.col2 FROM test1 t1 LEFT JOIN test2 t2 ON t1.col1 = t2.col1;";
    PlanNode logicalPlan = buildLogicalPlan(simpleQuery);
    // assertThat(logicalPlan instanceof OutputKafkaTopicNode);
    assertThat(logicalPlan.getSources().get(0), instanceOf(ProjectNode.class));
    assertThat(logicalPlan.getSources().get(0).getSources().get(0), instanceOf(JoinNode.class));
    assertThat(logicalPlan.getSources().get(0).getSources().get(0).getSources().get(0), instanceOf(StructuredDataSourceNode.class));
    assertThat(logicalPlan.getSources().get(0).getSources().get(0).getSources().get(1), instanceOf(StructuredDataSourceNode.class));
    assertThat(logicalPlan.getSchema().fields().size(), equalTo(4));
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) JoinNode(io.confluent.ksql.planner.plan.JoinNode) ProjectNode(io.confluent.ksql.planner.plan.ProjectNode) StructuredDataSourceNode(io.confluent.ksql.planner.plan.StructuredDataSourceNode) Test(org.junit.Test)

Example 23 with PlanNode

use of io.confluent.ksql.planner.plan.PlanNode 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

PlanNode (io.confluent.ksql.planner.plan.PlanNode)23 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)13 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)11 ProjectNode (io.confluent.ksql.planner.plan.ProjectNode)8 FilterNode (io.confluent.ksql.planner.plan.FilterNode)6 Expression (io.confluent.ksql.parser.tree.Expression)4 Statement (io.confluent.ksql.parser.tree.Statement)4 StructuredDataSourceNode (io.confluent.ksql.planner.plan.StructuredDataSourceNode)4 AggregateAnalysis (io.confluent.ksql.analyzer.AggregateAnalysis)3 Analysis (io.confluent.ksql.analyzer.Analysis)3 Pair (io.confluent.ksql.util.Pair)3 GenericRow (io.confluent.ksql.GenericRow)2 AggregateAnalyzer (io.confluent.ksql.analyzer.AggregateAnalyzer)2 AnalysisContext (io.confluent.ksql.analyzer.AnalysisContext)2 Analyzer (io.confluent.ksql.analyzer.Analyzer)2 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)2 AbstractStreamCreateStatement (io.confluent.ksql.parser.tree.AbstractStreamCreateStatement)2 DdlStatement (io.confluent.ksql.parser.tree.DdlStatement)2 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)2