Search in sources :

Example 6 with LongLiteral

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

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

the class ExpressionFormatterTest method shouldFormatRow.

@Test
public void shouldFormatRow() {
    final String result = ExpressionFormatter.formatExpression(new Row(Arrays.asList(new LongLiteral("1"), new QualifiedNameReference(QualifiedName.of(Arrays.asList("a", "b"))))));
    assertThat(result, equalTo("ROW (1, a.b)"));
}
Also used : LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Row(io.confluent.ksql.parser.tree.Row) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference) Test(org.junit.Test)

Example 8 with LongLiteral

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

the class AstBuilder method visitPrintTopic.

@Override
public Node visitPrintTopic(SqlBaseParser.PrintTopicContext context) {
    boolean fromBeginning = context.FROM() != null;
    QualifiedName topicName = null;
    if (context.STRING() != null) {
        topicName = QualifiedName.of(unquote(context.STRING().getText(), "'"));
    } else {
        topicName = getQualifiedName(context.qualifiedName());
    }
    if (context.number() == null) {
        return new PrintTopic(getLocation(context), topicName, fromBeginning, null);
    } else if (context.number() instanceof SqlBaseParser.IntegerLiteralContext) {
        SqlBaseParser.IntegerLiteralContext integerLiteralContext = (SqlBaseParser.IntegerLiteralContext) context.number();
        return new PrintTopic(getLocation(context), topicName, fromBeginning, (LongLiteral) visitIntegerLiteral(integerLiteralContext));
    } else {
        throw new KsqlException("Interval value should be integer in 'PRINT' command!");
    }
}
Also used : LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) QualifiedName(io.confluent.ksql.parser.tree.QualifiedName) PrintTopic(io.confluent.ksql.parser.tree.PrintTopic) KsqlException(io.confluent.ksql.util.KsqlException)

Aggregations

LongLiteral (io.confluent.ksql.parser.tree.LongLiteral)8 Test (org.junit.Test)7 StringLiteral (io.confluent.ksql.parser.tree.StringLiteral)5 WhenClause (io.confluent.ksql.parser.tree.WhenClause)4 QualifiedNameReference (io.confluent.ksql.parser.tree.QualifiedNameReference)2 SearchedCaseExpression (io.confluent.ksql.parser.tree.SearchedCaseExpression)2 SimpleCaseExpression (io.confluent.ksql.parser.tree.SimpleCaseExpression)2 BetweenPredicate (io.confluent.ksql.parser.tree.BetweenPredicate)1 ComparisonExpression (io.confluent.ksql.parser.tree.ComparisonExpression)1 DereferenceExpression (io.confluent.ksql.parser.tree.DereferenceExpression)1 Expression (io.confluent.ksql.parser.tree.Expression)1 PrintTopic (io.confluent.ksql.parser.tree.PrintTopic)1 QualifiedName (io.confluent.ksql.parser.tree.QualifiedName)1 Query (io.confluent.ksql.parser.tree.Query)1 Row (io.confluent.ksql.parser.tree.Row)1 Statement (io.confluent.ksql.parser.tree.Statement)1 KsqlException (io.confluent.ksql.util.KsqlException)1