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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations