Search in sources :

Example 6 with Analysis

use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.

the class ExpressionTypeManagerTest method testUDFExpr.

@Test
public void testUDFExpr() throws Exception {
    String simpleQuery = "SELECT FLOOR(col3), CEIL(col3*3), ABS(col0+1.34), RANDOM()+10, ROUND(col3*2)+12 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));
    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(exprType1.type() == Schema.Type.FLOAT64);
    Assert.assertTrue(exprType2.type() == Schema.Type.FLOAT64);
    Assert.assertTrue(exprType3.type() == Schema.Type.FLOAT64);
    Assert.assertTrue(exprType4.type() == Schema.Type.INT64);
}
Also used : Analysis(io.confluent.ksql.analyzer.Analysis) Schema(org.apache.kafka.connect.data.Schema) Test(org.junit.Test)

Example 7 with Analysis

use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.

the class ExpressionTypeManagerTest 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 8 with Analysis

use of io.confluent.ksql.analyzer.Analysis 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;
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) LogicalPlanner(io.confluent.ksql.planner.LogicalPlanner) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Expression(io.confluent.ksql.parser.tree.Expression) Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 9 with Analysis

use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.

the class LogicalPlannerTest 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;
}
Also used : PlanNode(io.confluent.ksql.planner.plan.PlanNode) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Expression(io.confluent.ksql.parser.tree.Expression) Statement(io.confluent.ksql.parser.tree.Statement) Analysis(io.confluent.ksql.analyzer.Analysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AggregateAnalysis(io.confluent.ksql.analyzer.AggregateAnalysis) AnalysisContext(io.confluent.ksql.analyzer.AnalysisContext) AggregateAnalyzer(io.confluent.ksql.analyzer.AggregateAnalyzer) Analyzer(io.confluent.ksql.analyzer.Analyzer)

Example 10 with Analysis

use of io.confluent.ksql.analyzer.Analysis in project ksql by confluentinc.

the class ExpressionTypeManagerTest method testStringUDFExpr.

@Test
public void testStringUDFExpr() throws Exception {
    String simpleQuery = "SELECT LCASE(col1), UCASE(col2), TRIM(col1), CONCAT(col1,'_test'), SUBSTRING(col1, 1, 3) 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));
    Schema exprType3 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(3));
    Schema exprType4 = expressionTypeManager.getExpressionType(analysis.getSelectExpressions().get(4));
    Assert.assertTrue(exprType0.type() == Schema.Type.STRING);
    Assert.assertTrue(exprType1.type() == Schema.Type.STRING);
    Assert.assertTrue(exprType2.type() == Schema.Type.STRING);
    Assert.assertTrue(exprType3.type() == Schema.Type.STRING);
    Assert.assertTrue(exprType4.type() == Schema.Type.STRING);
}
Also used : Analysis(io.confluent.ksql.analyzer.Analysis) Schema(org.apache.kafka.connect.data.Schema) 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