Search in sources :

Example 11 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral 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 12 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral 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 13 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatLogicalBinaryExpression.

@Test
public void shouldFormatLogicalBinaryExpression() {
    final LogicalBinaryExpression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, new StringLiteral("a"), new StringLiteral("b"));
    assertThat(ExpressionFormatter.formatExpression(expression), equalTo("('a' AND 'b')"));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.parser.tree.LogicalBinaryExpression) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) Test(org.junit.Test)

Example 14 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral 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)

Example 15 with StringLiteral

use of io.confluent.ksql.parser.tree.StringLiteral in project ksql by confluentinc.

the class ExpressionFormatterTest method shouldFormatFunctionWithDistinct.

@Test
public void shouldFormatFunctionWithDistinct() {
    final FunctionCall functionCall = new FunctionCall(new NodeLocation(1, 1), QualifiedName.of("function", "COUNT"), true, Collections.singletonList(new StringLiteral("name")));
    assertThat(ExpressionFormatter.formatExpression(functionCall), equalTo("function.COUNT(DISTINCT 'name')"));
}
Also used : NodeLocation(io.confluent.ksql.parser.tree.NodeLocation) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) FunctionCall(io.confluent.ksql.parser.tree.FunctionCall) Test(org.junit.Test)

Aggregations

StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)21 Test (org.junit.Test)16 Expression (io.confluent.ksql.parser.tree.Expression)8 HashMap (java.util.HashMap)7 LongLiteral (io.confluent.ksql.parser.tree.LongLiteral)5 TableElement (io.confluent.ksql.parser.tree.TableElement)5 CreateTable (io.confluent.ksql.parser.tree.CreateTable)4 FunctionCall (io.confluent.ksql.parser.tree.FunctionCall)4 WhenClause (io.confluent.ksql.parser.tree.WhenClause)4 KsqlException (io.confluent.ksql.util.KsqlException)4 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)3 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)3 CreateStream (io.confluent.ksql.parser.tree.CreateStream)2 HoppingWindowExpression (io.confluent.ksql.parser.tree.HoppingWindowExpression)2 LambdaExpression (io.confluent.ksql.parser.tree.LambdaExpression)2 LogicalBinaryExpression (io.confluent.ksql.parser.tree.LogicalBinaryExpression)2 NodeLocation (io.confluent.ksql.parser.tree.NodeLocation)2 RegisterTopic (io.confluent.ksql.parser.tree.RegisterTopic)2 TumblingWindowExpression (io.confluent.ksql.parser.tree.TumblingWindowExpression)2 WindowExpression (io.confluent.ksql.parser.tree.WindowExpression)2