use of io.confluent.ksql.parser.tree.QuerySpecification 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.QuerySpecification in project ksql by confluentinc.
the class KsqlParserTest method testUDF.
@Test
public void testUDF() throws Exception {
String queryStr = "SELECT lcase(col1), concat(col2,'hello'), floor(abs(col3)) FROM test1 t1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSelectAll fails", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testSelectAll 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("LCASE(T1.COL1)"));
SingleColumn column1 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(1);
Assert.assertTrue("testProjection fails", column1.getAlias().get().equalsIgnoreCase("KSQL_COL_1"));
Assert.assertTrue("testProjection fails", column1.getExpression().toString().equalsIgnoreCase("CONCAT(T1.COL2, 'hello')"));
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("FLOOR(ABS(T1.COL3))"));
}
use of io.confluent.ksql.parser.tree.QuerySpecification in project ksql by confluentinc.
the class KsqlParserTest method testSelectSessionWindow.
@Test
public void testSelectSessionWindow() throws Exception {
String queryStr = "select itemid, sum(orderunits) from orders window SESSION ( 30 second) where " + "orderunits > 5 group by itemid;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testSelectSessionWindow failed.", statement instanceof Query);
Query query = (Query) statement;
Assert.assertTrue("testSelectSessionWindow failed.", query.getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
Assert.assertTrue("testCreateTable failed.", querySpecification.getSelect().getSelectItems().size() == 2);
Assert.assertTrue("testSelectSessionWindow failed.", querySpecification.getWhere().get().toString().equalsIgnoreCase("(ORDERS.ORDERUNITS > 5)"));
Assert.assertTrue("testSelectSessionWindow failed.", ((AliasedRelation) querySpecification.getFrom()).getAlias().equalsIgnoreCase("ORDERS"));
Assert.assertTrue("testSelectSessionWindow failed.", querySpecification.getWindowExpression().isPresent());
Assert.assertTrue("testSelectSessionWindow failed.", querySpecification.getWindowExpression().get().toString().equalsIgnoreCase(" WINDOW STREAMWINDOW SESSION " + "( 30 SECONDS ) "));
}
use of io.confluent.ksql.parser.tree.QuerySpecification in project ksql by confluentinc.
the class KsqlParserTest method testCreateStreamAsSelect.
@Test
public void testCreateStreamAsSelect() throws Exception {
String queryStr = "CREATE STREAM bigorders_json WITH (value_format = 'json', " + "kafka_topic='bigorders_topic') AS SELECT * FROM orders WHERE orderunits > 5 ;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testCreateStreamAsSelect failed.", statement instanceof CreateStreamAsSelect);
CreateStreamAsSelect createStreamAsSelect = (CreateStreamAsSelect) statement;
Assert.assertTrue("testCreateTable failed.", createStreamAsSelect.getName().toString().equalsIgnoreCase("bigorders_json"));
Assert.assertTrue("testCreateTable failed.", createStreamAsSelect.getQuery().getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) createStreamAsSelect.getQuery().getQueryBody();
Assert.assertTrue("testCreateTable failed.", querySpecification.getSelect().getSelectItems().size() == 4);
Assert.assertTrue("testCreateTable failed.", querySpecification.getWhere().get().toString().equalsIgnoreCase("(ORDERS.ORDERUNITS > 5)"));
Assert.assertTrue("testCreateTable failed.", ((AliasedRelation) querySpecification.getFrom()).getAlias().equalsIgnoreCase("ORDERS"));
}
use of io.confluent.ksql.parser.tree.QuerySpecification in project ksql by confluentinc.
the class KsqlParserTest method testBooleanExpression.
@Test
public void testBooleanExpression() throws Exception {
String queryStr = "SELECT col0 = 10, col2, col3 > col1 FROM test1;";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testBooleanExpression 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("testBooleanExpression fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
Assert.assertTrue("testBooleanExpression fails", column0.getExpression().toString().equalsIgnoreCase("(TEST1.COL0 = 10)"));
}
Aggregations