Search in sources :

Example 1 with LongLiteral

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

the class QueryAnalyzerTest method shouldProcessHavingExpression.

@Test
public void shouldProcessHavingExpression() {
    final List<Statement> statements = ksqlParser.buildAst("select itemid, sum(orderunits) from orders window TUMBLING ( size 30 second) " + "where orderunits > 5 group by itemid having count(itemid) > 10;", metaStore);
    final Query query = (Query) statements.get(0);
    final Analysis analysis = queryAnalyzer.analyze("sqlExpression", query);
    final AggregateAnalysis aggregateAnalysis = queryAnalyzer.analyzeAggregate(query, analysis);
    final Expression havingExpression = aggregateAnalysis.getHavingExpression();
    assertThat(havingExpression, equalTo(new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, new QualifiedNameReference(QualifiedName.of("KSQL_AGG_VARIABLE_1")), new LongLiteral("10"))));
}
Also used : ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) Query(io.confluent.ksql.parser.tree.Query) ComparisonExpression(io.confluent.ksql.parser.tree.ComparisonExpression) DereferenceExpression(io.confluent.ksql.parser.tree.DereferenceExpression) Expression(io.confluent.ksql.parser.tree.Expression) LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Statement(io.confluent.ksql.parser.tree.Statement) QualifiedNameReference(io.confluent.ksql.parser.tree.QualifiedNameReference) Test(org.junit.Test)

Example 2 with LongLiteral

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

the class ExpressionFormatterTest method shouldFormatBetweenPredicate.

@Test
public void shouldFormatBetweenPredicate() {
    final BetweenPredicate predicate = new BetweenPredicate(new StringLiteral("blah"), new LongLiteral("5"), new LongLiteral("10"));
    assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('blah' BETWEEN 5 AND 10)"));
}
Also used : BetweenPredicate(io.confluent.ksql.parser.tree.BetweenPredicate) StringLiteral(io.confluent.ksql.parser.tree.StringLiteral) LongLiteral(io.confluent.ksql.parser.tree.LongLiteral) Test(org.junit.Test)

Example 3 with LongLiteral

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

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

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

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