Search in sources :

Example 1 with SimpleCaseExpression

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

the class ExpressionFormatterTest method shouldFormatSimpleCaseExpressionWithDefaultValue.

@Test
public void shouldFormatSimpleCaseExpressionWithDefaultValue() {
    final SimpleCaseExpression expression = new SimpleCaseExpression(new StringLiteral("operand"), Collections.singletonList(new WhenClause(new StringLiteral("foo"), new LongLiteral(1))), Optional.of(new LongLiteral(2)));
    assertThat(ExpressionFormatter.formatExpression(expression), equalTo("(CASE 'operand' WHEN 'foo' THEN 1 ELSE 2 END)"));
}
Also used : SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 2 with SimpleCaseExpression

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

the class ExpressionFormatterTest method shouldFormatSimpleCaseExpression.

@Test
public void shouldFormatSimpleCaseExpression() {
    final SimpleCaseExpression expression = new SimpleCaseExpression(new StringLiteral("operand"), Collections.singletonList(new WhenClause(new StringLiteral("foo"), new LongLiteral(1))), Optional.empty());
    assertThat(ExpressionFormatter.formatExpression(expression), equalTo("(CASE 'operand' WHEN 'foo' THEN 1 END)"));
}
Also used : SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Test(org.junit.Test)

Example 3 with SimpleCaseExpression

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

the class ExpressionTypeManagerTest method shouldThrowOnSimpleCase.

@Test
public void shouldThrowOnSimpleCase() {
    final Expression expression = new SimpleCaseExpression(TestExpressions.COL0, ImmutableList.of(new WhenClause(new IntegerLiteral(10), new StringLiteral("ten"))), Optional.empty());
    // When:
    assertThrows(UnsupportedOperationException.class, () -> expressionTypeManager.getExpressionSqlType(expression));
}
Also used : SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 4 with SimpleCaseExpression

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

the class SqlToJavaVisitorTest method shouldThrowOnSimpleCase.

@Test
public void shouldThrowOnSimpleCase() {
    // Given:
    final Expression expression = new SimpleCaseExpression(COL0, ImmutableList.of(new WhenClause(new IntegerLiteral(10), new StringLiteral("ten"))), empty());
    // When:
    assertThrows(UnsupportedOperationException.class, () -> sqlToJavaVisitor.process(expression));
}
Also used : SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 5 with SimpleCaseExpression

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

the class ExpressionTreeRewriterTest method shouldRewriteSimpleCaseExpression.

@Test
public void shouldRewriteSimpleCaseExpression() {
    // Given:
    final SimpleCaseExpression parsed = parseExpression("CASE COL0 WHEN 1 THEN 'ONE' WHEN 2 THEN 'TWO' ELSE 'THREE' END");
    when(processor.apply(parsed.getOperand(), context)).thenReturn(expr1);
    when(processor.apply(parsed.getWhenClauses().get(0), context)).thenReturn(when1);
    when(processor.apply(parsed.getWhenClauses().get(1), context)).thenReturn(when2);
    when(processor.apply(parsed.getDefaultValue().get(), context)).thenReturn(expr2);
    // When:
    final Expression rewritten = expressionRewriter.rewrite(parsed, context);
    // Then:
    assertThat(rewritten, equalTo(new SimpleCaseExpression(parsed.getLocation(), expr1, ImmutableList.of(when1, when2), Optional.of(expr2))));
}
Also used : SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) Test(org.junit.Test)

Aggregations

SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)5 Test (org.junit.Test)5 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)4 WhenClause (io.confluent.ksql.execution.expression.tree.WhenClause)4 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)3 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)3 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)3 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)3 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)3 Expression (io.confluent.ksql.execution.expression.tree.Expression)3 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)3 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)3 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)3 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)2 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)2 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)2 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)2 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)2 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)1