Search in sources :

Example 36 with Statement

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

Example 37 with Statement

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

Example 38 with Statement

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))]"));
}
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)

Example 39 with Statement

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

Example 40 with Statement

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

Aggregations

Statement (io.confluent.ksql.parser.tree.Statement)54 Test (org.junit.Test)38 Query (io.confluent.ksql.parser.tree.Query)24 QuerySpecification (io.confluent.ksql.parser.tree.QuerySpecification)18 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)7 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)7 KsqlException (io.confluent.ksql.util.KsqlException)7 Analysis (io.confluent.ksql.analyzer.Analysis)6 AnalysisContext (io.confluent.ksql.analyzer.AnalysisContext)6 Analyzer (io.confluent.ksql.analyzer.Analyzer)6 DdlStatement (io.confluent.ksql.parser.tree.DdlStatement)5 Expression (io.confluent.ksql.parser.tree.Expression)5 ArrayList (java.util.ArrayList)5 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)4 PlanNode (io.confluent.ksql.planner.plan.PlanNode)4 AggregateAnalysis (io.confluent.ksql.analyzer.AggregateAnalysis)3 AggregateAnalyzer (io.confluent.ksql.analyzer.AggregateAnalyzer)3 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)3 AbstractStreamCreateStatement (io.confluent.ksql.parser.tree.AbstractStreamCreateStatement)3 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)3