Search in sources :

Example 16 with Analysis

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;
}
Also used : Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 17 with 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));
}
Also used : ExpressionMetadata(io.confluent.ksql.util.ExpressionMetadata) GenericRowValueTypeEnforcer(io.confluent.ksql.util.GenericRowValueTypeEnforcer) Analysis(io.confluent.ksql.analyzer.Analysis) Test(org.junit.Test)

Example 18 with Analysis

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;
}
Also used : Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 19 with 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)"));
}
Also used : Analysis(io.confluent.ksql.analyzer.Analysis) Test(org.junit.Test)

Aggregations

Analysis (io.confluent.ksql.analyzer.Analysis)19 Test (org.junit.Test)11 AnalysisContext (io.confluent.ksql.analyzer.AnalysisContext)6 Analyzer (io.confluent.ksql.analyzer.Analyzer)6 Statement (io.confluent.ksql.parser.tree.Statement)6 ExpressionMetadata (io.confluent.ksql.util.ExpressionMetadata)6 AggregateAnalysis (io.confluent.ksql.analyzer.AggregateAnalysis)4 Schema (org.apache.kafka.connect.data.Schema)4 AggregateAnalyzer (io.confluent.ksql.analyzer.AggregateAnalyzer)3 Expression (io.confluent.ksql.parser.tree.Expression)3 LogicalPlanner (io.confluent.ksql.planner.LogicalPlanner)3 PlanNode (io.confluent.ksql.planner.plan.PlanNode)3 GenericRowValueTypeEnforcer (io.confluent.ksql.util.GenericRowValueTypeEnforcer)2 QueryAnalyzer (io.confluent.ksql.analyzer.QueryAnalyzer)1 KsqlStream (io.confluent.ksql.metastore.KsqlStream)1 StructuredDataSource (io.confluent.ksql.metastore.StructuredDataSource)1 KsqlStructuredDataOutputNode (io.confluent.ksql.planner.plan.KsqlStructuredDataOutputNode)1 AggregateExpressionRewriter (io.confluent.ksql.util.AggregateExpressionRewriter)1