Search in sources :

Example 1 with WhenClause

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;
}
Also used : WhenClause(io.confluent.ksql.parser.tree.WhenClause)

Example 2 with WhenClause

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)"));
}
Also used : SimpleCaseExpression(io.confluent.ksql.parser.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.parser.tree.WhenClause) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Test(org.junit.Test)

Example 3 with WhenClause

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)"));
}
Also used : SimpleCaseExpression(io.confluent.ksql.parser.tree.SimpleCaseExpression) WhenClause(io.confluent.ksql.parser.tree.WhenClause) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Test(org.junit.Test)

Example 4 with WhenClause

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)"));
}
Also used : WhenClause(io.confluent.ksql.parser.tree.WhenClause) SearchedCaseExpression(io.confluent.ksql.parser.tree.SearchedCaseExpression) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Test(org.junit.Test)

Example 5 with WhenClause

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)"));
}
Also used : WhenClause(io.confluent.ksql.parser.tree.WhenClause) SearchedCaseExpression(io.confluent.ksql.parser.tree.SearchedCaseExpression) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Test(org.junit.Test)

Aggregations

WhenClause (io.confluent.ksql.parser.tree.WhenClause)5 LongLiteral (io.confluent.ksql.parser.tree.LongLiteral)4 StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)4 Test (org.junit.Test)4 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)2 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)2