Search in sources :

Example 46 with SingleStatementContext

use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.

the class AstBuilderTest method shouldHandleAliasQualifiedSelect.

@Test
public void shouldHandleAliasQualifiedSelect() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT T.COL0 FROM TEST2 T;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(column(SourceName.of("T"), "COL0"), Optional.empty())))));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) Select(io.confluent.ksql.parser.tree.Select) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) Test(org.junit.Test)

Example 47 with SingleStatementContext

use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.

the class AstBuilderTest method shouldHandleQualifiedSelectStarOnLeftJoinSource.

@Test
public void shouldHandleQualifiedSelectStarOnLeftJoinSource() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT TEST1.* FROM TEST1 JOIN TEST2 WITHIN 1 SECOND ON TEST1.ID = TEST2.ID;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new AllColumns(Optional.of(TEST1_NAME))))));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) Select(io.confluent.ksql.parser.tree.Select) AllColumns(io.confluent.ksql.parser.tree.AllColumns) Test(org.junit.Test)

Example 48 with SingleStatementContext

use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.

the class AstBuilderTest method shouldSupportHeadersColumns.

@Test
public void shouldSupportHeadersColumns() {
    // Given:
    final SingleStatementContext stmt = givenQuery("CREATE STREAM INPUT (K ARRAY<STRUCT<key STRING, value BYTES>> HEADERS) WITH (kafka_topic='input',value_format='JSON');");
    // When:
    final CreateStream createStream = (CreateStream) builder.buildStatement(stmt);
    // Then:
    final TableElement column = Iterators.getOnlyElement(createStream.getElements().iterator());
    assertThat(column.getConstraints(), is((new ColumnConstraints.Builder()).headers().build()));
}
Also used : SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) ColumnConstraints(io.confluent.ksql.parser.tree.ColumnConstraints) CreateStream(io.confluent.ksql.parser.tree.CreateStream) TableElement(io.confluent.ksql.parser.tree.TableElement) Test(org.junit.Test)

Example 49 with SingleStatementContext

use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.

the class AstBuilderTest method shouldExtractMultipleUnaliasedJoinDataSources.

@Test
public void shouldExtractMultipleUnaliasedJoinDataSources() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1 " + "JOIN TEST2 ON test1.col1 = test2.col1 " + "JOIN TEST3 ON test1.col1 = test3.col1;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat(result.getFrom(), is(instanceOf(Join.class)));
    assertThat((Join) result.getFrom(), hasLeft(new AliasedRelation(TEST1, TEST1_NAME)));
    assertThat((Join) result.getFrom(), hasRights(new AliasedRelation(TEST2, TEST2_NAME), new AliasedRelation(TEST3, TEST3_NAME)));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) AliasedRelation(io.confluent.ksql.parser.tree.AliasedRelation) Test(org.junit.Test)

Example 50 with SingleStatementContext

use of io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext in project ksql by confluentinc.

the class AstBuilderTest method shouldOmitSelectAliasIfNotPresent.

@Test
public void shouldOmitSelectAliasIfNotPresent() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT COL0 FROM TEST1;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(column("COL0"), Optional.empty())))));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) Select(io.confluent.ksql.parser.tree.Select) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) Test(org.junit.Test)

Aggregations

SingleStatementContext (io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext)51 Test (org.junit.Test)50 Query (io.confluent.ksql.parser.tree.Query)37 Select (io.confluent.ksql.parser.tree.Select)17 QueryContainer (io.confluent.ksql.parser.tree.QueryContainer)9 SingleColumn (io.confluent.ksql.parser.tree.SingleColumn)9 AliasedRelation (io.confluent.ksql.parser.tree.AliasedRelation)8 AllColumns (io.confluent.ksql.parser.tree.AllColumns)8 KsqlException (io.confluent.ksql.util.KsqlException)7 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)5 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)4 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)4 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)4 CreateStream (io.confluent.ksql.parser.tree.CreateStream)4 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)2 LambdaVariable (io.confluent.ksql.execution.expression.tree.LambdaVariable)2 ColumnConstraints (io.confluent.ksql.parser.tree.ColumnConstraints)2 CreateTable (io.confluent.ksql.parser.tree.CreateTable)2 TableElement (io.confluent.ksql.parser.tree.TableElement)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2