use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testSetProperties.
@Test
public void testSetProperties() throws Exception {
String simpleQuery = "set 'auto.offset.reset'='earliest';";
Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
Assert.assertTrue(statement instanceof SetProperty);
SetProperty setProperty = (SetProperty) statement;
Assert.assertTrue(setProperty.toString().equalsIgnoreCase("SetProperty{}"));
Assert.assertTrue(setProperty.getPropertyName().equalsIgnoreCase("auto.offset.reset"));
Assert.assertTrue(setProperty.getPropertyValue().equalsIgnoreCase("earliest"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testLiterals.
@Test
public void testLiterals() throws Exception {
String queryStr = "SELECT 10, col2, 'test', 2.5, true, -5 FROM test1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testLiterals fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testLiterals fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testLiterals fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testLiterals fails", column0.getExpression().toString().equalsIgnoreCase("10"));
SingleColumn column1 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(1);
Assert.assertTrue("testLiterals fails", column1.getAlias().get().equalsIgnoreCase("COL2"));
Assert.assertTrue("testLiterals fails", column1.getExpression().toString().equalsIgnoreCase("TEST1.COL2"));
SingleColumn column2 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(2);
Assert.assertTrue("testLiterals fails", column2.getAlias().get().equalsIgnoreCase("KSQL_COL_2"));
Assert.assertTrue("testLiterals fails", column2.getExpression().toString().equalsIgnoreCase("'test'"));
SingleColumn column3 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(3);
Assert.assertTrue("testLiterals fails", column3.getAlias().get().equalsIgnoreCase("KSQL_COL_3"));
Assert.assertTrue("testLiterals fails", column3.getExpression().toString().equalsIgnoreCase("2.5"));
SingleColumn column4 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(4);
Assert.assertTrue("testLiterals fails", column4.getAlias().get().equalsIgnoreCase("KSQL_COL_4"));
Assert.assertTrue("testLiterals fails", column4.getExpression().toString().equalsIgnoreCase("true"));
SingleColumn column5 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(5);
Assert.assertTrue("testLiterals fails", column5.getAlias().get().equalsIgnoreCase("KSQL_COL_5"));
Assert.assertTrue("testLiterals fails", column5.getExpression().toString().equalsIgnoreCase("-5"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testShowProperties.
@Test
public void testShowProperties() throws Exception {
String simpleQuery = "SHOW PROPERTIES;";
Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
Assert.assertTrue(statement instanceof ListProperties);
ListProperties listProperties = (ListProperties) statement;
Assert.assertTrue(listProperties.toString().equalsIgnoreCase("ListProperties{}"));
}
use of io.confluent.ksql.parser.tree.Statement 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.parser.tree.Statement in project ksql by confluentinc.
the class AstBuilder method visitExplain.
@Override
public Node visitExplain(SqlBaseParser.ExplainContext ctx) {
SqlBaseParser.QualifiedNameContext qualifiedName = ctx.qualifiedName();
String queryId = null;
if (qualifiedName != null) {
queryId = qualifiedName.getText();
}
Statement statement = null;
if (ctx.statement() != null) {
statement = (Statement) visit(ctx.statement());
}
return new Explain(queryId, statement, false, Arrays.asList());
}
Aggregations