Search in sources :

Example 1 with PlanNode

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

the class LogicalPlannerTest method testSimpleQueryLogicalPlan.

@Test
public void testSimpleQueryLogicalPlan() throws Exception {
    String simpleQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
    PlanNode logicalPlan = buildLogicalPlan(simpleQuery);
    // Assert.assertTrue(logicalPlan instanceof OutputKafkaTopicNode);
    assertThat(logicalPlan.getSources().get(0), instanceOf(ProjectNode.class));
    assertThat(logicalPlan.getSources().get(0).getSources().get(0), instanceOf(FilterNode.class));
    assertThat(logicalPlan.getSources().get(0).getSources().get(0).getSources().get(0), instanceOf(StructuredDataSourceNode.class));
    assertThat(logicalPlan.getSchema().fields().size(), equalTo(3));
    Assert.assertNotNull(((FilterNode) logicalPlan.getSources().get(0).getSources().get(0)).getPredicate());
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) FilterNode(io.confluent.ksql.planner.plan.FilterNode) ProjectNode(io.confluent.ksql.planner.plan.ProjectNode) StructuredDataSourceNode(io.confluent.ksql.planner.plan.StructuredDataSourceNode) Test(org.junit.Test)

Example 2 with PlanNode

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

the class LogicalPlannerTest method testComplexAggregateLogicalPlan.

@Test
public void testComplexAggregateLogicalPlan() throws Exception {
    String simpleQuery = "SELECT col0, sum(floor(col3)*100)/count(col3) FROM test1 window " + "HOPPING ( size 2 second, advance by 1 second) " + "WHERE col0 > 100 GROUP BY col0;";
    PlanNode logicalPlan = buildLogicalPlan(simpleQuery);
    assertThat(logicalPlan.getSources().get(0), instanceOf(AggregateNode.class));
    AggregateNode aggregateNode = (AggregateNode) logicalPlan.getSources().get(0);
    assertThat(aggregateNode.getFunctionList().size(), equalTo(2));
    assertThat(aggregateNode.getFunctionList().get(0).getName().getSuffix(), equalTo("SUM"));
    assertThat(aggregateNode.getWindowExpression().getKsqlWindowExpression().toString(), equalTo(" HOPPING ( SIZE 2 SECONDS , ADVANCE BY 1 SECONDS ) "));
    assertThat(aggregateNode.getGroupByExpressions().size(), equalTo(1));
    assertThat(aggregateNode.getGroupByExpressions().get(0).toString(), equalTo("TEST1.COL0"));
    assertThat(aggregateNode.getRequiredColumnList().size(), equalTo(2));
    assertThat(aggregateNode.getSchema().fields().get(1).schema().type(), equalTo(Schema.Type.FLOAT64));
    assertThat(logicalPlan.getSources().get(0).getSchema().fields().size(), equalTo(2));
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) AggregateNode(io.confluent.ksql.planner.plan.AggregateNode) Test(org.junit.Test)

Example 3 with PlanNode

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

the class LogicalPlannerTest method testSimpleLeftJoinFilterLogicalPlan.

@Test
public void testSimpleLeftJoinFilterLogicalPlan() throws Exception {
    String simpleQuery = "SELECT t1.col1, t2.col1, col5, t2.col4, t2.col2 FROM test1 t1 LEFT JOIN test2 t2 ON " + "t1.col1 = t2.col1 WHERE t1.col1 > 10 AND t2.col4 = 10.8;";
    PlanNode logicalPlan = buildLogicalPlan(simpleQuery);
    assertThat(logicalPlan.getSources().get(0), instanceOf(ProjectNode.class));
    ProjectNode projectNode = (ProjectNode) logicalPlan.getSources().get(0);
    assertThat(projectNode.getKeyField().name(), equalTo("t1.col1".toUpperCase()));
    assertThat(projectNode.getSchema().fields().size(), equalTo(5));
    assertThat(projectNode.getSources().get(0), instanceOf(FilterNode.class));
    FilterNode filterNode = (FilterNode) projectNode.getSources().get(0);
    assertThat(filterNode.getPredicate().toString(), equalTo("((T1.COL1 > 10) AND (T2.COL4 = 10.8))"));
    assertThat(filterNode.getSources().get(0), instanceOf(JoinNode.class));
    JoinNode joinNode = (JoinNode) filterNode.getSources().get(0);
    assertThat(joinNode.getSources().get(0), instanceOf(StructuredDataSourceNode.class));
    assertThat(joinNode.getSources().get(1), instanceOf(StructuredDataSourceNode.class));
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) JoinNode(io.confluent.ksql.planner.plan.JoinNode) FilterNode(io.confluent.ksql.planner.plan.FilterNode) ProjectNode(io.confluent.ksql.planner.plan.ProjectNode) StructuredDataSourceNode(io.confluent.ksql.planner.plan.StructuredDataSourceNode) Test(org.junit.Test)

Example 4 with PlanNode

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

the class LogicalPlannerTest method testSimpleAggregateLogicalPlan.

@Test
public void testSimpleAggregateLogicalPlan() throws Exception {
    String simpleQuery = "SELECT col0, sum(col3), count(col3) FROM test1 window TUMBLING ( size 2 " + "second) " + "WHERE col0 > 100 GROUP BY col0;";
    PlanNode logicalPlan = buildLogicalPlan(simpleQuery);
    assertThat(logicalPlan.getSources().get(0), instanceOf(AggregateNode.class));
    AggregateNode aggregateNode = (AggregateNode) logicalPlan.getSources().get(0);
    assertThat(aggregateNode.getFunctionList().size(), equalTo(2));
    assertThat(aggregateNode.getFunctionList().get(0).getName().getSuffix(), equalTo("SUM"));
    assertThat(aggregateNode.getWindowExpression().getKsqlWindowExpression().toString(), equalTo(" TUMBLING ( SIZE 2 SECONDS ) "));
    assertThat(aggregateNode.getGroupByExpressions().size(), equalTo(1));
    assertThat(aggregateNode.getGroupByExpressions().get(0).toString(), equalTo("TEST1.COL0"));
    assertThat(aggregateNode.getRequiredColumnList().size(), equalTo(2));
    assertThat(aggregateNode.getSchema().fields().get(1).schema().type(), equalTo(Schema.Type.FLOAT64));
    assertThat(aggregateNode.getSchema().fields().get(2).schema().type(), equalTo(Schema.Type.INT64));
    assertThat(logicalPlan.getSources().get(0).getSchema().fields().size(), equalTo(3));
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) AggregateNode(io.confluent.ksql.planner.plan.AggregateNode) Test(org.junit.Test)

Example 5 with PlanNode

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

the class SchemaKStreamTest method testSelectSchemaKStream.

@Test
public void testSelectSchemaKStream() throws Exception {
    String selectQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
    PlanNode logicalPlan = planBuilder.buildLogicalPlan(selectQuery);
    ProjectNode projectNode = (ProjectNode) logicalPlan.getSources().get(0);
    initialSchemaKStream = new SchemaKStream(logicalPlan.getTheSourceNode().getSchema(), kStream, ksqlStream.getKeyField(), new ArrayList<>(), SchemaKStream.Type.SOURCE, functionRegistry, new MockSchemaRegistryClient());
    List<Pair<String, Expression>> projectNameExpressionPairList = projectNode.getProjectNameExpressionPairList();
    SchemaKStream projectedSchemaKStream = initialSchemaKStream.select(projectNameExpressionPairList);
    Assert.assertTrue(projectedSchemaKStream.getSchema().fields().size() == 3);
    Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL0") == projectedSchemaKStream.getSchema().fields().get(0));
    Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL2") == projectedSchemaKStream.getSchema().fields().get(1));
    Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL3") == projectedSchemaKStream.getSchema().fields().get(2));
    Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL0").schema().type() == Schema.Type.INT64);
    Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL2").schema().type() == Schema.Type.STRING);
    Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL3").schema().type() == Schema.Type.FLOAT64);
    Assert.assertTrue(projectedSchemaKStream.getSourceSchemaKStreams().get(0) == initialSchemaKStream);
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) ArrayList(java.util.ArrayList) ProjectNode(io.confluent.ksql.planner.plan.ProjectNode) Pair(io.confluent.ksql.util.Pair) Test(org.junit.Test)

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