use of io.confluent.ksql.parser.tree.WhenClause in project ksql by confluentinc.
the class DefaultTraversalVisitor method visitSimpleCaseExpression.
@Override
protected R visitSimpleCaseExpression(SimpleCaseExpression node, C context) {
process(node.getOperand(), context);
for (WhenClause clause : node.getWhenClauses()) {
process(clause, context);
}
node.getDefaultValue().ifPresent(value -> process(value, context));
return null;
}
use of io.confluent.ksql.parser.tree.WhenClause 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.parser.tree.WhenClause 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.parser.tree.WhenClause in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatSearchedCaseExpression.
@Test
public void shouldFormatSearchedCaseExpression() {
final SearchedCaseExpression expression = new SearchedCaseExpression(Collections.singletonList(new WhenClause(new StringLiteral("foo"), new LongLiteral("1"))), Optional.empty());
assertThat(ExpressionFormatter.formatExpression(expression), equalTo("(CASE WHEN 'foo' THEN 1 END)"));
}
use of io.confluent.ksql.parser.tree.WhenClause in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatSearchedCaseExpressionWithDefaultValue.
@Test
public void shouldFormatSearchedCaseExpressionWithDefaultValue() {
final SearchedCaseExpression expression = new SearchedCaseExpression(Collections.singletonList(new WhenClause(new StringLiteral("foo"), new LongLiteral("1"))), Optional.of(new LongLiteral("2")));
assertThat(ExpressionFormatter.formatExpression(expression), equalTo("(CASE WHEN 'foo' THEN 1 ELSE 2 END)"));
}
Aggregations