Search in sources :

Example 31 with SingleStatementContext

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

the class AstBuilderTest method shouldRejectIncorrectlyTypedSingleHeaderColumns.

@Test
public void shouldRejectIncorrectlyTypedSingleHeaderColumns() {
    // Given:
    final SingleStatementContext stmt = givenQuery("CREATE STREAM INPUT (K BIGINT HEADER('abc')) WITH (kafka_topic='input',value_format='JSON');");
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> {
        builder.buildStatement(stmt);
    });
    // Then:
    assertThat(e.getMessage(), is("Invalid type for HEADER('abc') column: expected BYTES, got BIGINT"));
}
Also used : SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 32 with SingleStatementContext

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

the class AstBuilderTest method shouldHandleUnqualifiedSelectStar.

@Test
public void shouldHandleUnqualifiedSelectStar() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new AllColumns(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) AllColumns(io.confluent.ksql.parser.tree.AllColumns) Test(org.junit.Test)

Example 33 with SingleStatementContext

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

the class AstBuilderTest method shouldSupportExplicitEmitChangesForInsertInto.

@Test
public void shouldSupportExplicitEmitChangesForInsertInto() {
    // Given:
    final SingleStatementContext stmt = givenQuery("INSERT INTO TEST1 SELECT * FROM TEST2 EMIT CHANGES;");
    // When:
    final Query result = ((QueryContainer) builder.buildStatement(stmt)).getQuery();
    // Then:
    assertThat("Should be push", result.isPullQuery(), is(false));
    assertThat(result.getRefinement().get().getOutputRefinement(), is(OutputRefinement.CHANGES));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) QueryContainer(io.confluent.ksql.parser.tree.QueryContainer) Test(org.junit.Test)

Example 34 with SingleStatementContext

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

the class AstBuilderTest method shouldExtractUnaliasedJoinDataSources.

@Test
public void shouldExtractUnaliasedJoinDataSources() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1 JOIN TEST2" + " ON test1.col1 = test2.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)));
}
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 35 with SingleStatementContext

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

the class AstBuilderTest method shouldExtractAsAliasedJoinDataSources.

@Test
public void shouldExtractAsAliasedJoinDataSources() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1 AS t1 JOIN TEST2 AS t2" + " ON t1.col1 = t2.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, SourceName.of("T1"))));
    assertThat((Join) result.getFrom(), hasRights(new AliasedRelation(TEST2, SourceName.of("T2"))));
}
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)

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