Search in sources :

Example 11 with Statement

use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.

the class KsqlParserTest method testSimpleQuery.

@Test
public void testSimpleQuery() throws Exception {
    String simpleQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100;";
    Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
    Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
    Query query = (Query) statement;
    Assert.assertTrue("testSimpleQuery fails", query.getQueryBody() instanceof QuerySpecification);
    QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
    Assert.assertTrue("testSimpleQuery fails", querySpecification.getSelect().getSelectItems().size() == 3);
    assertThat(querySpecification.getFrom(), not(nullValue()));
    Assert.assertTrue("testSimpleQuery fails", querySpecification.getWhere().isPresent());
    Assert.assertTrue("testSimpleQuery fails", querySpecification.getWhere().get() instanceof ComparisonExpression);
    ComparisonExpression comparisonExpression = (ComparisonExpression) querySpecification.getWhere().get();
    Assert.assertTrue("testSimpleQuery fails", comparisonExpression.getType().getValue().equalsIgnoreCase(">"));
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) Query(io.confluent.ksql.parser.tree.Query) Statement(io.confluent.ksql.parser.tree.Statement) Test(org.junit.Test)

Example 12 with Statement

use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.

the class KsqlParserTest method testSimpleLeftJoin.

@Test
public void testSimpleLeftJoin() throws Exception {
    String queryStr = "SELECT t1.col1, t2.col1, t2.col4, col5, t2.col2 FROM test1 t1 LEFT JOIN test2 t2 ON " + "t1.col1 = t2.col1;";
    Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
    Assert.assertTrue("testSimpleQuery fails", statement instanceof Query);
    Query query = (Query) statement;
    Assert.assertTrue("testSimpleLeftJoin fails", query.getQueryBody() instanceof QuerySpecification);
    QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
    Assert.assertTrue("testSimpleLeftJoin fails", querySpecification.getFrom() instanceof Join);
    Join join = (Join) querySpecification.getFrom();
    Assert.assertTrue("testSimpleLeftJoin fails", join.getType().toString().equalsIgnoreCase("LEFT"));
    Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation) join.getLeft()).getAlias().equalsIgnoreCase("T1"));
    Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation) join.getRight()).getAlias().equalsIgnoreCase("T2"));
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) Query(io.confluent.ksql.parser.tree.Query) Statement(io.confluent.ksql.parser.tree.Statement) Join(io.confluent.ksql.parser.tree.Join) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) Test(org.junit.Test)

Example 13 with Statement

use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.

the class KsqlParserTest method testBinaryExpression.

@Test
public void testBinaryExpression() throws Exception {
    String queryStr = "SELECT col0+10, col2, col3-col1 FROM test1;";
    Statement statement = KSQL_PARSER.buildAst(queryStr, metaStore).get(0);
    Assert.assertTrue("testBinaryExpression fails", statement instanceof Query);
    Query query = (Query) statement;
    Assert.assertTrue("testBinaryExpression fails", query.getQueryBody() instanceof QuerySpecification);
    QuerySpecification querySpecification = (QuerySpecification) query.getQueryBody();
    SingleColumn column0 = (SingleColumn) querySpecification.getSelect().getSelectItems().get(0);
    Assert.assertTrue("testBinaryExpression fails", column0.getAlias().get().equalsIgnoreCase("KSQL_COL_0"));
    Assert.assertTrue("testBinaryExpression fails", column0.getExpression().toString().equalsIgnoreCase("(TEST1.COL0 + 10)"));
}
Also used : QuerySpecification(io.confluent.ksql.parser.tree.QuerySpecification) Query(io.confluent.ksql.parser.tree.Query) Statement(io.confluent.ksql.parser.tree.Statement) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) Test(org.junit.Test)

Example 14 with Statement

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

Example 15 with Statement

use of io.confluent.ksql.parser.tree.Statement in project ksql by confluentinc.

the class KsqlParserTest method testShowTopics.

@Test
public void testShowTopics() throws Exception {
    String simpleQuery = "SHOW TOPICS;";
    Statement statement = KSQL_PARSER.buildAst(simpleQuery, metaStore).get(0);
    Assert.assertTrue(statement instanceof ListTopics);
    ListTopics listTopics = (ListTopics) statement;
    Assert.assertTrue(listTopics.toString().equalsIgnoreCase("ListTopics{}"));
}
Also used : ListTopics(io.confluent.ksql.parser.tree.ListTopics) 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