Search in sources :

Example 11 with SingleStatementContext

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

the class AstBuilderTest method shouldBuildIntervalUnit.

@Test
public void shouldBuildIntervalUnit() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT TIMESTAMPADD(MINUTES, 5, Col4) FROM TEST1;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TIMESTAMPADD"), ImmutableList.of(new IntervalUnit(TimeUnit.MINUTES), new IntegerLiteral(5), column("COL4"))), Optional.empty())))));
}
Also used : IntervalUnit(io.confluent.ksql.execution.expression.tree.IntervalUnit) 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) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 12 with SingleStatementContext

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

the class AstBuilderTest method shouldCreateNormalStream.

@Test
public void shouldCreateNormalStream() {
    // Given:
    final SingleStatementContext stmt = givenQuery("CREATE STREAM X WITH (kafka_topic='X');");
    // When:
    final CreateStream result = (CreateStream) builder.buildStatement(stmt);
    // Then:
    assertThat(result.isSource(), is(false));
}
Also used : SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) CreateStream(io.confluent.ksql.parser.tree.CreateStream) Test(org.junit.Test)

Example 13 with SingleStatementContext

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

the class AstBuilderTest method shouldHandleUnqualifiedSelectStarOnJoin.

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

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

the class AstBuilderTest method shouldRejectIncorrectlyTypedHeadersColumns.

@Test
public void shouldRejectIncorrectlyTypedHeadersColumns() {
    // Given:
    final SingleStatementContext stmt = givenQuery("CREATE STREAM INPUT (K BIGINT HEADERS) 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 HEADERS column: expected ARRAY<STRUCT<`KEY` STRING, `VALUE` BYTES>>, got BIGINT"));
}
Also used : SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 15 with SingleStatementContext

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

the class AstBuilderTest method shouldDefaultToEmptyRefinementForBareQueries.

@Test
public void shouldDefaultToEmptyRefinementForBareQueries() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT * FROM TEST1;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat("Should be pull", result.isPullQuery(), is(true));
    assertThat(result.getRefinement(), is(Optional.empty()));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) 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