use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testSimpleQuery.
@Test
public void testSimpleQuery() throws Exception {
String simpleQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testSimpleQuery fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
Assert.assertTrue("testSimpleQuery fails", querySpecification.getSelect().getSelectItems().size() == 3);
assertThat(querySpecification.getFrom(), not(nullValue()));
Assert.assertTrue("testSimpleQuery fails", querySpecification.getWhere().isPresent());
Assert.assertTrue("testSimpleQuery fails", querySpecification.getWhere().get() instanceof ComparisonExpression);
ComparisonExpression comparisonExpression = (ComparisonExpression) querySpecification.getWhere().get();
Assert.assertTrue("testSimpleQuery fails", comparisonExpression.getType().getValue().equalsIgnoreCase(">"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testSimpleLeftJoin.
@Test
public void testSimpleLeftJoin() throws Exception {
String queryStr = "SELECT t1.col1, t2.col1, t2.col4, col5, t2.col2 FROM test1 t1 LEFT JOIN test2 t2 ON " + "t1.col1 = t2.col1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testSimpleLeftJoin fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
Assert.assertTrue("testSimpleLeftJoin fails", querySpecification.getFrom() instanceof Join);
Join join = (Join) querySpecification.getFrom();
Assert.assertTrue("testSimpleLeftJoin fails", join.getType().toString().equalsIgnoreCase("LEFT"));
Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation) join.getLeft()).getAlias().equalsIgnoreCase("T1"));
Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation) join.getRight()).getAlias().equalsIgnoreCase("T2"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testBinaryExpression.
@Test
public void testBinaryExpression() throws Exception {
String queryStr = "SELECT col0+10, col2, col3-col1 FROM test1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testBinaryExpression fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testBinaryExpression fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testBinaryExpression fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testBinaryExpression fails", column0.getExpression().toString().equalsIgnoreCase("(TEST1.COL0 + 10)"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testBooleanLogicalExpression.
@Test
public void testBooleanLogicalExpression() throws Exception {
String queryStr = "SELECT 10, col2, 'test', 2.5, true, -5 FROM test1 WHERE col1 = 10 AND col2 LIKE 'val' OR col4 > 2.6 ;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testProjection fails", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
Assert.assertTrue("testProjection fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testProjection fails", column0.getExpression().toString().equalsIgnoreCase("10"));
SingleColumn column1 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(1);
Assert.assertTrue("testProjection fails", column1.getAlias().get().equalsIgnoreCase("COL2"));
Assert.assertTrue("testProjection fails", column1.getExpression().toString().equalsIgnoreCase("TEST1.COL2"));
SingleColumn column2 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(2);
Assert.assertTrue("testProjection fails", column2.getAlias().get().equalsIgnoreCase("KSQL_COL_2"));
Assert.assertTrue("testProjection fails", column2.getExpression().toString().equalsIgnoreCase("'test'"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testShowTopics.
@Test
public void testShowTopics() throws Exception {
String simpleQuery = "SHOW TOPICS;";
Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
Assert.assertTrue(statement instanceof ListTopics);
ListTopics listTopics = (ListTopics) statement;
Assert.assertTrue(listTopics.toString().equalsIgnoreCase("ListTopics{}"));
}
Aggregations