Search in sources :

Example 6 with SingleStatementContext

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

the class AstBuilderTest method shouldThrowOnUnknownStarAliasOnJoin.

@Test
public void shouldThrowOnUnknownStarAliasOnJoin() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT unknown.* FROM TEST1 JOIN TEST2 WITHIN 1 SECOND ON TEST1.ID = TEST2.ID;");
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> builder.buildStatement(stmt));
    // Then:
    assertThat(e.getMessage(), containsString("'UNKNOWN' is not a valid stream/table name or alias."));
}
Also used : SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 7 with SingleStatementContext

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

the class AstBuilderTest method shouldFailOnPersistentQueryLimitClauseTable.

@Test
public void shouldFailOnPersistentQueryLimitClauseTable() {
    // Given:
    final SingleStatementContext stmt = givenQuery("CREATE TABLE X AS SELECT * FROM TEST1 LIMIT 5;");
    // Then:
    Exception exception = assertThrows(KsqlException.class, () -> {
        builder.buildStatement(stmt);
    });
    String expectedMessage = "CREATE TABLE AS SELECT statements don't support LIMIT clause.";
    String actualMessage = exception.getMessage();
    assertEquals(expectedMessage, actualMessage);
}
Also used : SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) Matchers.containsString(org.hamcrest.Matchers.containsString) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 8 with SingleStatementContext

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

the class AstBuilderTest method shouldSupportExplicitEmitChangesOnBareQuery.

@Test
public void shouldSupportExplicitEmitChangesOnBareQuery() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1 EMIT CHANGES;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // 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) Test(org.junit.Test)

Example 9 with SingleStatementContext

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

the class AstBuilderTest method shouldHandleQualifiedSelectStar.

@Test
public void shouldHandleQualifiedSelectStar() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT TEST1.* FROM TEST1;");
    // 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 10 with SingleStatementContext

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

the class AstBuilderTest method shouldDefaultToEmitChangesForCtas.

@Test
public void shouldDefaultToEmitChangesForCtas() {
    // Given:
    final SingleStatementContext stmt = givenQuery("CREATE TABLE X AS SELECT COUNT(1) FROM TEST1 GROUP BY ROWKEY;");
    // 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)

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