use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class AstBuilder method visitStatements.
@Override
public Node visitStatements(SqlBaseParser.StatementsContext context) {
List<Statement> statementList = new ArrayList<>();
for (SqlBaseParser.SingleStatementContext singleStatementContext : context.singleStatement()) {
Statement statement = (Statement) visitSingleStatement(singleStatementContext);
statementList.add(statement);
}
return new Statements(statementList);
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldCreateAnalysisForSimpleQuery.
@Test
public void shouldCreateAnalysisForSimpleQuery() {
final List<Statement> statements = ksqlParser.buildAst("select orderid from orders;", metaStore);
final Analysis analysis = queryAnalyzer.analyze("sqlExpression", (Query) statements.get(0));
final Pair<StructuredDataSource, String> fromDataSource = analysis.getFromDataSource(0);
assertThat(analysis.getSelectExpressions(), equalTo(Collections.singletonList(new DereferenceExpression(new QualifiedNameReference(QualifiedName.of("ORDERS")), "ORDERID"))));
assertThat(analysis.getFromDataSources().size(), equalTo(1));
assertThat(fromDataSource.left, instanceOf(KsqlStream.class));
assertThat(fromDataSource.right, equalTo("ORDERS"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldThrowExceptionIfNonAggregateSelectsDontMatchGroupBySize.
@Test
public void shouldThrowExceptionIfNonAggregateSelectsDontMatchGroupBySize() {
final List<Statement> statements = ksqlParser.buildAst("select itemid, orderid, sum(orderunits) from orders window TUMBLING ( size 30 second) " + "where orderunits > 5 group by itemid;", metaStore);
final Query query = (Query) statements.get(0);
final Analysis analysis = queryAnalyzer.analyze("sqlExpression", query);
try {
queryAnalyzer.analyzeAggregate(query, analysis);
fail("should have thrown KsqlException as aggregate query doesn't have a groupby clause");
} catch (KsqlException e) {
// ok
}
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldFailWithIncorrectJoinCriteria.
@Test
public void shouldFailWithIncorrectJoinCriteria() {
final List<Statement> statements = ksqlParser.buildAst("select * from test1 join test2 on test1.col1 = test2.coll;", metaStore);
final Query query = (Query) statements.get(0);
try {
queryAnalyzer.analyze("sqlExpression", query);
} catch (KsqlException ex) {
assertThat(ex.getMessage().trim(), equalTo("Line: 1, Col: 46 : Invalid join criteria (TEST1.COL1 = TEST2.COLL). Key for TEST2 is not set correctly."));
}
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class QueryAnalyzerTest method shouldThrowExceptionIfAggregateAnalysisDoesntHaveGroupBy.
@Test
public void shouldThrowExceptionIfAggregateAnalysisDoesntHaveGroupBy() {
final List<Statement> statements = ksqlParser.buildAst("select itemid, sum(orderunits) from orders window TUMBLING ( size 30 second) " + "where orderunits > 5;", metaStore);
final Query query = (Query) statements.get(0);
final Analysis analysis = queryAnalyzer.analyze("sqlExpression", query);
try {
queryAnalyzer.analyzeAggregate(query, analysis);
fail("should have thrown KsqlException as aggregate query doesn't have a groupby clause");
} catch (KsqlException e) {
// ok
}
}
Aggregations