Search in sources :

Example 16 with SearchedCaseExpression

use of io.confluent.ksql.execution.expression.tree.SearchedCaseExpression in project ksql by confluentinc.

the class KsqlParserTest method getSearchedCaseExpressionFromCsas.

private static SearchedCaseExpression getSearchedCaseExpressionFromCsas(final Statement statement) {
    final Query query = ((CreateStreamAsSelect) statement).getQuery();
    final Expression caseExpression = ((SingleColumn) query.getSelect().getSelectItems().get(0)).getExpression();
    return (SearchedCaseExpression) caseExpression;
}
Also used : Query(io.confluent.ksql.parser.tree.Query) TerminateQuery(io.confluent.ksql.parser.tree.TerminateQuery) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) WithinExpression(io.confluent.ksql.parser.tree.WithinExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) CreateStreamAsSelect(io.confluent.ksql.parser.tree.CreateStreamAsSelect) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn)

Example 17 with SearchedCaseExpression

use of io.confluent.ksql.execution.expression.tree.SearchedCaseExpression in project ksql by confluentinc.

the class KsqlParserTest method shouldBuildSearchedCaseWithoutDefaultStatement.

@Test
public void shouldBuildSearchedCaseWithoutDefaultStatement() {
    // Given:
    final String statementString = "CREATE STREAM S AS SELECT CASE WHEN orderunits < 10 THEN 'small' WHEN orderunits < 100 THEN 'medium' END FROM orders;";
    // When:
    final Statement statement = KsqlParserTestUtil.buildSingleAst(statementString, metaStore).getStatement();
    // Then:
    final SearchedCaseExpression searchedCaseExpression = getSearchedCaseExpressionFromCsas(statement);
    assertThat(searchedCaseExpression.getDefaultValue().isPresent(), equalTo(false));
}
Also used : SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)17 Test (org.junit.Test)15 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)13 Expression (io.confluent.ksql.execution.expression.tree.Expression)13 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)13 WhenClause (io.confluent.ksql.execution.expression.tree.WhenClause)13 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)12 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)12 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)12 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)11 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)11 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)9 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)8 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)7 KsqlException (io.confluent.ksql.util.KsqlException)5 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4