use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class CodeGenRunnerTest method analyzeQuery.
private Analysis analyzeQuery(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(queryStr, analysis, metaStore);
analyzer.process(statements.get(0), new AnalysisContext(null));
return analysis;
}
use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class CodeGenRunnerTest method testU1DFExpr.
@Test
public void testU1DFExpr() throws Exception {
String simpleQuery = "SELECT FLOOR(col3), CEIL(col3*3), ABS(col0+1.34), RANDOM()+10, ROUND(col3*2)+12 FROM codegen_test;";
Analysis analysis = analyzeQuery(simpleQuery);
GenericRowValueTypeEnforcer genericRowValueTypeEnforcer = new GenericRowValueTypeEnforcer(schema);
ExpressionMetadata expressionEvaluator0 = codeGenRunner.buildCodeGenFromParseTree(analysis.getSelectExpressions().get(0));
Object argObj0 = genericRowValueTypeEnforcer.enforceFieldType(3, 1.5);
Object result0 = expressionEvaluator0.getExpressionEvaluator().evaluate(new Object[] { expressionEvaluator0.getUdfs()[0], argObj0 });
assertThat(argObj0, instanceOf(Double.class));
assertThat(result0, instanceOf(Double.class));
assertThat(((Double) result0), equalTo(1.0));
ExpressionMetadata expressionEvaluator1 = codeGenRunner.buildCodeGenFromParseTree(analysis.getSelectExpressions().get(1));
Object argObj1 = genericRowValueTypeEnforcer.enforceFieldType(3, 1.5);
Object result1 = evaluateU1DF(expressionEvaluator1, argObj1);
assertThat(argObj1, instanceOf(Double.class));
assertThat(result1, instanceOf(Double.class));
assertThat(((Double) result1), equalTo(5.0));
ExpressionMetadata expressionEvaluator2 = codeGenRunner.buildCodeGenFromParseTree(analysis.getSelectExpressions().get(2));
Object argObj2 = genericRowValueTypeEnforcer.enforceFieldType(0, 15);
Object result2 = evaluateU1DF(expressionEvaluator2, argObj2);
assertThat(argObj2, instanceOf(Long.class));
assertThat(result2, instanceOf(Double.class));
assertThat(((Double) result2), equalTo(16.34));
ExpressionMetadata expressionEvaluator3 = codeGenRunner.buildCodeGenFromParseTree(analysis.getSelectExpressions().get(3));
Object result3 = expressionEvaluator3.getExpressionEvaluator().evaluate(new Object[] { expressionEvaluator3.getUdfs()[0] });
assertThat(result3, instanceOf(Double.class));
assertThat(((Double) result3).intValue(), equalTo(10));
ExpressionMetadata expressionEvaluator4 = codeGenRunner.buildCodeGenFromParseTree(analysis.getSelectExpressions().get(4));
Object argObj4 = genericRowValueTypeEnforcer.enforceFieldType(3, 1.5);
Object result4 = evaluateU1DF(expressionEvaluator4, argObj4);
assertThat(argObj4, instanceOf(Double.class));
assertThat(result4, instanceOf(Long.class));
assertThat(((Long) result4), equalTo(15L));
}
use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class SqlToJavaVisitorTest method analyzeQuery.
private Analysis analyzeQuery(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));
return analysis;
}
use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.
the class SqlToJavaVisitorTest method processBasicJavaMath.
@Test
public void processBasicJavaMath() throws Exception {
String simpleQuery = "SELECT col0+col3, col2, col3+10, col0*25, 12*4+2 FROM test1 WHERE col0 > 100;";
Analysis analysis = analyzeQuery(simpleQuery);
String javaExpression = new SqlToJavaVisitor(schema, functionRegistry).process(analysis.getSelectExpressions().get(0));
assertThat(javaExpression, equalTo("(TEST1_COL0 + TEST1_COL3)"));
}
Aggregations