Search in sources :

Example 1 with CreateStreamAsSelect

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"));
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) Statement(io.confluent.ksql.parser.tree.Statement) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) Test(org.junit.Test)

Example 2 with CreateStreamAsSelect

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))]"));
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) Statement(io.confluent.ksql.parser.tree.Statement) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) Test(org.junit.Test)

Aggregations

CreateStreamAsSelect (io.confluent.ksql.parser.tree.CreateStreamAsSelect)2 QuerySpecification (io.confluent.ksql.parser.tree.QuerySpecification)2 Statement (io.confluent.ksql.parser.tree.Statement)2 Test (org.junit.Test)2 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)1