use of io.confluent.ksql.parser.tree.CreateStreamAsSelect 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.CreateStreamAsSelect in project ksql by confluentinc.
the class KsqlParserTest method testSelectSinkProperties.
@Test
public void testSelectSinkProperties() throws Exception {
String simpleQuery = "create stream s1 with (timestamp='orderid', partitions = 3) as select " + "col1, col2" + " from orders where col2 is null and col3 is not null or (col3*col2 = " + "12);";
Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
Assert.assertTrue("testSelectTumblingWindow failed.", statement instanceof CreateStreamAsSelect);
CreateStreamAsSelect createStreamAsSelect = (CreateStreamAsSelect) statement;
Assert.assertTrue("testSelectTumblingWindow failed.", createStreamAsSelect.getQuery().getQueryBody() instanceof QuerySpecification);
QuerySpecification querySpecification = (QuerySpecification) createStreamAsSelect.getQuery().getQueryBody();
Assert.assertTrue(querySpecification.getWhere().toString().equalsIgnoreCase("Optional[(((ORDERS.COL2 IS NULL) AND (ORDERS.COL3 IS NOT NULL)) OR ((ORDERS.COL3 * ORDERS.COL2) = 12))]"));
}
Aggregations