use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class ExpressionTypeManagerTest method testArithmaticExpr.
@Test
public void testArithmaticExpr() throws Exception {
String simpleQuery = "SELECT col0+col3, col2, col3+10, col0+10, col0*25 FROM test1 WHERE col0 > 100;";
Analysis analysis = analyzeQuery(simpleQuery);
ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
Schema exprType0 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(0));
Schema exprType2 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(2));
Schema exprType3 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(3));
Schema exprType4 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(4));
Assert.assertTrue(exprType0.type() == Schema.Type.FLOAT64);
Assert.assertTrue(exprType2.type() == Schema.Type.FLOAT64);
Assert.assertTrue(exprType3.type() == Schema.Type.INT64);
Assert.assertTrue(exprType4.type() == Schema.Type.INT64);
}
use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class ExpressionTypeManagerTest method testComparisonExpr.
@Test
public void testComparisonExpr() throws Exception {
String simpleQuery = "SELECT col0>col3, col0*25<200, col2 = 'test' FROM test1;";
Analysis analysis = analyzeQuery(simpleQuery);
ExpressionTypeManager expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
Schema exprType0 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(0));
Schema exprType1 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(1));
Schema exprType2 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(2));
Assert.assertTrue(exprType0.type() == Schema.Type.BOOLEAN);
Assert.assertTrue(exprType1.type() == Schema.Type.BOOLEAN);
Assert.assertTrue(exprType2.type() == Schema.Type.BOOLEAN);
}
use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class QueryEngine method buildQueryLogicalPlan.
private PlanNode buildQueryLogicalPlan(String sqlExpression, final Query query, final MetaStore tempMetaStore) {
final QueryAnalyzer queryAnalyzer = new QueryAnalyzer(tempMetaStore, ksqlEngine.getFunctionRegistry());
final Analysis analysis = queryAnalyzer.analyze(sqlExpression, query);
final AggregateAnalysis aggAnalysis = queryAnalyzer.analyzeAggregate(query, analysis);
final PlanNode logicalPlan = new LogicalPlanner(analysis, aggAnalysis, ksqlEngine.getFunctionRegistry()).buildPlan();
if (logicalPlan instanceof KsqlStructuredDataOutputNode) {
KsqlStructuredDataOutputNode ksqlStructuredDataOutputNode = (KsqlStructuredDataOutputNode) logicalPlan;
StructuredDataSource structuredDataSource = new KsqlStream(sqlExpression, ksqlStructuredDataOutputNode.getId().toString(), ksqlStructuredDataOutputNode.getSchema(), ksqlStructuredDataOutputNode.getKeyField(), ksqlStructuredDataOutputNode.getTimestampField() == null ? ksqlStructuredDataOutputNode.getTheSourceNode().getTimestampField() : ksqlStructuredDataOutputNode.getTimestampField(), ksqlStructuredDataOutputNode.getKsqlTopic());
tempMetaStore.putTopic(ksqlStructuredDataOutputNode.getKsqlTopic());
tempMetaStore.putSource(structuredDataSource.cloneWithTimeKeyColumns());
}
return logicalPlan;
}
use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class CodeGenRunnerTest method evalBooleanExpr.
private boolean evalBooleanExpr(String queryFormat, int cola, int colb, Object[] values) throws Exception {
String simpleQuery = String.format(queryFormat, cola, colb);
Analysis analysis = analyzeQuery(simpleQuery);
ExpressionMetadata expressionEvaluatorMetadata0 = codeGenRunner.buildCodeGenFromParseTree(analysis.getSelectExpressions().get(0));
assertThat(expressionEvaluatorMetadata0.getIndexes().length, equalTo(2));
int idx0 = expressionEvaluatorMetadata0.getIndexes()[0];
int idx1 = expressionEvaluatorMetadata0.getIndexes()[1];
assertThat(idx0, anyOf(equalTo(cola), equalTo(colb)));
assertThat(idx1, anyOf(equalTo(cola), equalTo(colb)));
assertThat(idx0, not(equalTo(idx1)));
if (idx0 == colb) {
Object tmp = values[0];
values[0] = values[1];
values[1] = tmp;
}
assertThat(expressionEvaluatorMetadata0.getUdfs().length, equalTo(2));
Object result0 = expressionEvaluatorMetadata0.getExpressionEvaluator().evaluate(values);
assertThat(result0, instanceOf(Boolean.class));
return (Boolean) result0;
}
use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class CodeGenRunnerTest method testIsNull.
@Test
public void testIsNull() throws Exception {
String simpleQuery = "SELECT col0 IS NULL FROM CODEGEN_TEST;";
Analysis analysis = analyzeQuery(simpleQuery);
ExpressionMetadata expressionEvaluatorMetadata0 = codeGenRunner.buildCodeGenFromParseTree(analysis.getSelectExpressions().get(0));
assertThat(expressionEvaluatorMetadata0.getIndexes().length, equalTo(1));
int idx0 = expressionEvaluatorMetadata0.getIndexes()[0];
assertThat(idx0, equalTo(0));
assertThat(expressionEvaluatorMetadata0.getUdfs().length, equalTo(1));
Object result0 = expressionEvaluatorMetadata0.getExpressionEvaluator().evaluate(new Object[] { null });
assertThat(result0, instanceOf(Boolean.class));
assertThat((Boolean) result0, is(true));
result0 = expressionEvaluatorMetadata0.getExpressionEvaluator().evaluate(new Object[] { 12345L });
assertThat(result0, instanceOf(Boolean.class));
Assert.assertThat((Boolean) result0, is(false));
}
Aggregations