use of io.confluent.ksql.planner.plan.ProjectNode 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));
}
use of io.confluent.ksql.planner.plan.ProjectNode 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);
}
use of io.confluent.ksql.planner.plan.ProjectNode in project ksql by confluentinc.
the class SchemaKTableTest 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);
initialSchemaKTable = new SchemaKTable(logicalPlan.getTheSourceNode().getSchema(), kTable, ksqlTable.getKeyField(), new ArrayList<>(), false, SchemaKStream.Type.SOURCE, functionRegistry, new MockSchemaRegistryClient());
SchemaKTable projectedSchemaKStream = initialSchemaKTable.select(projectNode.getProjectNameExpressionPairList());
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) == initialSchemaKTable);
}
use of io.confluent.ksql.planner.plan.ProjectNode in project ksql by confluentinc.
the class LogicalPlanner method buildProjectNode.
private ProjectNode buildProjectNode(final Schema inputSchema, final PlanNode sourcePlanNode) {
SchemaBuilder projectionSchema = 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);
projectionSchema = projectionSchema.field(alias, expressionType);
}
return new ProjectNode(new PlanNodeId("Project"), sourcePlanNode, projectionSchema, analysis.getSelectExpressions());
}
use of io.confluent.ksql.planner.plan.ProjectNode in project ksql by confluentinc.
the class SchemaKStreamTest method testSelectWithExpression.
@Test
public void testSelectWithExpression() throws Exception {
String selectQuery = "SELECT col0, LEN(UCASE(col2)), col3*3+5 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());
SchemaKStream projectedSchemaKStream = initialSchemaKStream.select(projectNode.getProjectNameExpressionPairList());
Assert.assertTrue(projectedSchemaKStream.getSchema().fields().size() == 3);
Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL0") == projectedSchemaKStream.getSchema().fields().get(0));
Assert.assertTrue(projectedSchemaKStream.getSchema().field("KSQL_COL_1") == projectedSchemaKStream.getSchema().fields().get(1));
Assert.assertTrue(projectedSchemaKStream.getSchema().field("KSQL_COL_2") == projectedSchemaKStream.getSchema().fields().get(2));
Assert.assertTrue(projectedSchemaKStream.getSchema().field("COL0").schema().type() == Schema.Type.INT64);
Assert.assertTrue(projectedSchemaKStream.getSchema().fields().get(1).schema().type() == Schema.Type.INT32);
Assert.assertTrue(projectedSchemaKStream.getSchema().fields().get(2).schema().type() == Schema.Type.FLOAT64);
Assert.assertTrue(projectedSchemaKStream.getSourceSchemaKStreams().get(0) == initialSchemaKStream);
}
Aggregations