use of io.confluent.ksql.planner.plan.PlanNode 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);
}
use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.
the class SqlPredicateTest method buildLogicalPlan.
private PlanNode buildLogicalPlan(String queryStr) {
List<Statement> statements = KSQL_PARSER.buildAst(queryStr, metaStore);
// Analyze the query to resolve the references and extract oeprations
Analysis analysis = new Analysis();
Analyzer analyzer = new Analyzer("sqlExpression", analysis, metaStore);
analyzer.process(statements.get(0), new AnalysisContext(null));
AggregateAnalysis aggregateAnalysis = new AggregateAnalysis();
AggregateAnalyzer aggregateAnalyzer = new AggregateAnalyzer(aggregateAnalysis, analysis, functionRegistry);
for (Expression expression : analysis.getSelectExpressions()) {
aggregateAnalyzer.process(expression, new AnalysisContext(null));
}
// Build a logical plan
PlanNode logicalPlan = new LogicalPlanner(analysis, aggregateAnalysis, functionRegistry).buildPlan();
return logicalPlan;
}
use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.
the class SqlPredicateTest method testFilter.
@Test
public void testFilter() throws Exception {
String selectQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
PlanNode logicalPlan = 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());
SqlPredicate predicate = new SqlPredicate(filterNode.getPredicate(), initialSchemaKStream.getSchema(), false, functionRegistry);
Assert.assertTrue(predicate.getFilterExpression().toString().equalsIgnoreCase("(TEST1.COL0 > 100)"));
Assert.assertTrue(predicate.getColumnIndexes().length == 1);
}
use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.
the class SqlPredicateTest method testFilterBiggerExpression.
@Test
public void testFilterBiggerExpression() throws Exception {
String selectQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100 AND LEN(col2) = 5;";
PlanNode logicalPlan = 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());
SqlPredicate predicate = new SqlPredicate(filterNode.getPredicate(), initialSchemaKStream.getSchema(), false, functionRegistry);
Assert.assertTrue(predicate.getFilterExpression().toString().equalsIgnoreCase("((TEST1.COL0 > 100) AND" + " (LEN(TEST1.COL2) = 5))"));
Assert.assertTrue(predicate.getColumnIndexes().length == 3);
}
use of io.confluent.ksql.planner.plan.PlanNode in project ksql by confluentinc.
the class LogicalPlannerTest method shouldCreatePlanWithTableAsSource.
@Test
public void shouldCreatePlanWithTableAsSource() {
PlanNode planNode = buildLogicalPlan("select col0 from TEST2 limit 5;");
assertThat(planNode.getSources().size(), equalTo(1));
StructuredDataSource structuredDataSource = ((StructuredDataSourceNode) planNode.getSources().get(0).getSources().get(0)).getStructuredDataSource();
assertThat(structuredDataSource.getDataSourceType(), equalTo(DataSource.DataSourceType.KTABLE));
assertThat(structuredDataSource.getName(), equalTo("TEST2"));
}
Aggregations