use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testDrop.
@Test
public void testDrop() throws Exception {
String simpleQuery = "DROP STREAM STREAM1; DROP TABLE TABLE1;";
List<Statement> statements = KSQL_PARSER.buildAst(simpleQuery, metaStore);
Statement statement0 = statements.get(0);
Statement statement1 = statements.get(1);
Assert.assertTrue(statement0 instanceof DropStream);
Assert.assertTrue(statement1 instanceof DropTable);
DropStream dropStream = (DropStream) statement0;
DropTable dropTable = (DropTable) statement1;
Assert.assertTrue(dropStream.getName().toString().equalsIgnoreCase("STREAM1"));
Assert.assertTrue(dropTable.getName().toString().equalsIgnoreCase("TABLE1"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testCreateTableWithTopic.
@Test
public void testCreateTableWithTopic() throws Exception {
String queryStr = "CREATE TABLE users (usertime bigint, userid varchar, regionid varchar, gender varchar) WITH (registered_topic = 'users_topic', key='userid', statestore='user_statestore');";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testRegisterTopic failed.", statement instanceof CreateTable);
CreateTable createTable = (CreateTable) statement;
Assert.assertTrue("testCreateTable failed.", createTable.getName().toString().equalsIgnoreCase("USERS"));
Assert.assertTrue("testCreateTable failed.", createTable.getElements().size() == 4);
Assert.assertTrue("testCreateTable failed.", createTable.getElements().get(0).getName().toString().equalsIgnoreCase("usertime"));
Assert.assertTrue("testCreateTable failed.", createTable.getProperties().get(DdlConfig.TOPIC_NAME_PROPERTY).toString().equalsIgnoreCase("'users_topic'"));
}
use of io.confluent.ksql.parser.tree.Statement 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))]"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testCreateStream.
@Test
public void testCreateStream() throws Exception {
String queryStr = "CREATE STREAM orders (ordertime bigint, orderid varchar, itemid varchar, orderunits " + "double) WITH (value_format = 'avro', " + "avroschemafile='/Users/hojjat/avro_order_schema.avro',kafka_topic='orders_topic');";
Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
Assert.assertTrue("testCreateStream failed.", statement instanceof CreateStream);
CreateStream createStream = (CreateStream) statement;
Assert.assertTrue("testCreateStream failed.", createStream.getName().toString().equalsIgnoreCase("ORDERS"));
Assert.assertTrue("testCreateStream failed.", createStream.getElements().size() == 4);
Assert.assertTrue("testCreateStream failed.", createStream.getElements().get(0).getName().toString().equalsIgnoreCase("ordertime"));
Assert.assertTrue("testCreateStream failed.", createStream.getProperties().get(DdlConfig.KAFKA_TOPIC_NAME_PROPERTY).toString().equalsIgnoreCase("'orders_topic'"));
Assert.assertTrue("testCreateStream failed.", createStream.getProperties().get(DdlConfig.VALUE_FORMAT_PROPERTY).toString().equalsIgnoreCase("'avro'"));
Assert.assertTrue("testCreateStream failed.", createStream.getProperties().get(DdlConfig.AVRO_SCHEMA_FILE).toString().equalsIgnoreCase("'/Users/hojjat/avro_order_schema.avro'"));
}
use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.
the class KsqlParserTest method testShowStreams.
@Test
public void testShowStreams() throws Exception {
String simpleQuery = "SHOW STREAMS;";
Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
Assert.assertTrue(statement instanceof ListStreams);
ListStreams listStreams = (ListStreams) statement;
Assert.assertTrue(listStreams.toString().equalsIgnoreCase("ListStreams{}"));
}
Aggregations