use of io.confluent.ksql.planner.plan.PlanNode 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.PlanNode in project ksql by confluentinc.
the class QueryEngine method buildLogicalPlans.
List<Pair<String, PlanNode>> buildLogicalPlans(final MetaStore metaStore, final List<Pair<String, Statement>> statementList) {
List<Pair<String, PlanNode>> logicalPlansList = new ArrayList<>();
// TODO: the purpose of tempMetaStore here
MetaStore tempMetaStore = metaStore.clone();
for (Pair<String, Statement> statementQueryPair : statementList) {
if (statementQueryPair.getRight() instanceof Query) {
PlanNode logicalPlan = buildQueryLogicalPlan(statementQueryPair.getLeft(), (Query) statementQueryPair.getRight(), tempMetaStore);
logicalPlansList.add(new Pair<>(statementQueryPair.getLeft(), logicalPlan));
} else {
logicalPlansList.add(new Pair<>(statementQueryPair.getLeft(), null));
}
log.info("Build logical plan for {}.", statementQueryPair.getLeft());
}
return logicalPlansList;
}
use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.
the class QueryEngine method buildPhysicalPlans.
List<QueryMetadata> buildPhysicalPlans(final List<Pair<String, PlanNode>> logicalPlans, final List<Pair<String, Statement>> statementList, final Map<String, Object> overriddenProperties, final boolean updateMetastore) throws Exception {
List<QueryMetadata> physicalPlans = new ArrayList<>();
for (int i = 0; i < logicalPlans.size(); i++) {
Pair<String, PlanNode> statementPlanPair = logicalPlans.get(i);
if (statementPlanPair.getRight() == null) {
Statement statement = statementList.get(i).getRight();
if (!(statement instanceof DdlStatement)) {
throw new KsqlException("expecting a statement implementing DDLStatement but got: " + statement.getClass());
}
handleDdlStatement(statementPlanPair.getLeft(), (DdlStatement) statement, overriddenProperties);
} else {
buildQueryPhysicalPlan(physicalPlans, statementPlanPair, overriddenProperties, updateMetastore);
}
}
return physicalPlans;
}
use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.
the class SchemaKStreamTest method testGroupByKey.
@Test
public void testGroupByKey() {
String selectQuery = "SELECT col0, col1 FROM test1 WHERE col0 > 100;";
PlanNode logicalPlan = planBuilder.buildLogicalPlan(selectQuery);
initialSchemaKStream = new SchemaKStream(logicalPlan.getTheSourceNode().getSchema(), kStream, ksqlStream.getKeyField(), new ArrayList<>(), SchemaKStream.Type.SOURCE, functionRegistry, new MockSchemaRegistryClient());
Expression keyExpression = new DereferenceExpression(new QualifiedNameReference(QualifiedName.of("TEST1")), "COL0");
KsqlTopicSerDe ksqlTopicSerDe = new KsqlJsonTopicSerDe();
Serde<GenericRow> rowSerde = ksqlTopicSerDe.getGenericRowSerde(initialSchemaKStream.getSchema(), null, false, null);
List<Expression> groupByExpressions = Arrays.asList(keyExpression);
SchemaKGroupedStream groupedSchemaKStream = initialSchemaKStream.groupBy(Serdes.String(), rowSerde, groupByExpressions);
Assert.assertEquals(groupedSchemaKStream.getKeyField().name(), "COL0");
}
use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.
the class SchemaKStreamTest method testFilter.
@Test
public void testFilter() throws Exception {
String selectQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
PlanNode logicalPlan = planBuilder.buildLogicalPlan(selectQuery);
FilterNode filterNode = (FilterNode) logicalPlan.getSources().get(0).getSources().get(0);
initialSchemaKStream = new SchemaKStream(logicalPlan.getTheSourceNode().getSchema(), kStream, ksqlStream.getKeyField(), new ArrayList<>(), SchemaKStream.Type.SOURCE, functionRegistry, new MockSchemaRegistryClient());
SchemaKStream filteredSchemaKStream = initialSchemaKStream.filter(filterNode.getPredicate());
Assert.assertTrue(filteredSchemaKStream.getSchema().fields().size() == 6);
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL0") == filteredSchemaKStream.getSchema().fields().get(0));
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL1") == filteredSchemaKStream.getSchema().fields().get(1));
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL2") == filteredSchemaKStream.getSchema().fields().get(2));
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL3") == filteredSchemaKStream.getSchema().fields().get(3));
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL0").schema().type() == Schema.Type.INT64);
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL1").schema().type() == Schema.Type.STRING);
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL2").schema().type() == Schema.Type.STRING);
Assert.assertTrue(filteredSchemaKStream.getSchema().field("TEST1.COL3").schema().type() == Schema.Type.FLOAT64);
Assert.assertTrue(filteredSchemaKStream.getSourceSchemaKStreams().get(0) == initialSchemaKStream);
}
Aggregations