Search in sources :

Example 6 with ProjectNode

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

the class SchemaKTableTest 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);
    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("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() == Schema.INT32_SCHEMA);
    Assert.assertTrue(projectedSchemaKStream.getSchema().fields().get(2).schema() == Schema.FLOAT64_SCHEMA);
    Assert.assertTrue(projectedSchemaKStream.getSourceSchemaKStreams().get(0) == initialSchemaKTable);
}
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) Test(org.junit.Test)

Example 7 with ProjectNode

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

the class SelectValueMapperTest method createMapper.

private SelectValueMapper createMapper(final String query) throws Exception {
    final PlanNode planNode = planBuilder.buildLogicalPlan(query);
    final ProjectNode projectNode = (ProjectNode) planNode.getSources().get(0);
    final Schema schema = planNode.getTheSourceNode().getSchema();
    final List<Pair<String, Expression>> expressionPairList = projectNode.getProjectNameExpressionPairList();
    final List<ExpressionMetadata> metadata = createExpressionMetadata(expressionPairList, schema);
    return new SelectValueMapper(new GenericRowValueTypeEnforcer(schema), expressionPairList, metadata);
}
Also used : ExpressionMetadata(io.confluent.ksql.util.ExpressionMetadata) PlanNode(io.confluent.ksql.planner.plan.PlanNode) GenericRowValueTypeEnforcer(io.confluent.ksql.util.GenericRowValueTypeEnforcer) Schema(org.apache.kafka.connect.data.Schema) ProjectNode(io.confluent.ksql.planner.plan.ProjectNode) Pair(io.confluent.ksql.util.Pair)

Aggregations

ProjectNode (io.confluent.ksql.planner.plan.ProjectNode)7 PlanNode (io.confluent.ksql.planner.plan.PlanNode)6 Test (org.junit.Test)5 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)4 ArrayList (java.util.ArrayList)4 Pair (io.confluent.ksql.util.Pair)2 Schema (org.apache.kafka.connect.data.Schema)2 Expression (io.confluent.ksql.parser.tree.Expression)1 FilterNode (io.confluent.ksql.planner.plan.FilterNode)1 JoinNode (io.confluent.ksql.planner.plan.JoinNode)1 PlanNodeId (io.confluent.ksql.planner.plan.PlanNodeId)1 StructuredDataSourceNode (io.confluent.ksql.planner.plan.StructuredDataSourceNode)1 ExpressionMetadata (io.confluent.ksql.util.ExpressionMetadata)1 ExpressionTypeManager (io.confluent.ksql.util.ExpressionTypeManager)1 GenericRowValueTypeEnforcer (io.confluent.ksql.util.GenericRowValueTypeEnforcer)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1