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