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)"));
}
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)"));
}
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));
}
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));
}
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))));
}
Aggregations