Search in sources :

Example 1 with AggregateNode

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

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

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

the class LogicalPlanner method buildAggregateNode.

private AggregateNode buildAggregateNode(final Schema inputSchema, final PlanNode sourcePlanNode) {
    SchemaBuilder aggregateSchema = SchemaBuilder.struct();
    ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(inputSchema, functionRegistry);
    for (int i = 0; i < analysis.getSelectExpressions().size(); i++) {
        Expression expression = analysis.getSelectExpressions().get(i);
        String alias = analysis.getSelectExpressionAlias().get(i);
        Schema expressionType = expressionTypeManager.getExpressionType(expression);
        aggregateSchema = aggregateSchema.field(alias, expressionType);
    }
    return new AggregateNode(new PlanNodeId("Aggregate"), sourcePlanNode, aggregateSchema, analysis.getGroupByExpressions(), analysis.getWindowExpression(), aggregateAnalysis.getAggregateFunctionArguments(), aggregateAnalysis.getFunctionList(), aggregateAnalysis.getRequiredColumnsList(), aggregateAnalysis.getFinalSelectExpressions(), aggregateAnalysis.getHavingExpression());
}
Also used : PlanNodeId(io.confluent.ksql.planner.plan.PlanNodeId) ExpressionTypeManager(io.confluent.ksql.util.ExpressionTypeManager) AggregateNode(io.confluent.ksql.planner.plan.AggregateNode) Expression(io.confluent.ksql.parser.tree.Expression) Schema(org.apache.kafka.connect.data.Schema) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder)

Aggregations

AggregateNode (io.confluent.ksql.planner.plan.AggregateNode)3 PlanNode (io.confluent.ksql.planner.plan.PlanNode)2 Test (org.junit.Test)2 Expression (io.confluent.ksql.parser.tree.Expression)1 PlanNodeId (io.confluent.ksql.planner.plan.PlanNodeId)1 ExpressionTypeManager (io.confluent.ksql.util.ExpressionTypeManager)1 Schema (org.apache.kafka.connect.data.Schema)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1