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;
}
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));
}
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;
}
Aggregations