Search in sources :

Example 16 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.

the class PullQueryRewriter method rewrite.

public static Expression rewrite(final Expression expression) {
    final Expression pseudoTimestamp = new StatementRewriteForMagicPseudoTimestamp().rewrite(expression);
    final Expression betweenPredicatesRemoved = rewriteBetweenPredicates(pseudoTimestamp);
    final Expression inPredicatesRemoved = rewriteInPredicates(betweenPredicatesRemoved);
    return LogicRewriter.rewriteDNF(inPredicatesRemoved);
}
Also used : Expression(io.confluent.ksql.execution.expression.tree.Expression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) StatementRewriteForMagicPseudoTimestamp(io.confluent.ksql.engine.rewrite.StatementRewriteForMagicPseudoTimestamp)

Example 17 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.

the class FlatMapNodeTest method shouldResolveNoneUdtfSelectExpressionToSelf.

@Test
public void shouldResolveNoneUdtfSelectExpressionToSelf() {
    // Given:
    final Expression exp = mock(Expression.class);
    // When:
    final Expression result = flatMapNode.resolveSelect(0, exp);
    // Then:
    assertThat(result, is(exp));
}
Also used : Expression(io.confluent.ksql.execution.expression.tree.Expression) Test(org.junit.Test)

Example 18 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.

the class ImplicitlyCastResolverTest method shouldCastToDecimal.

@Test
public void shouldCastToDecimal() {
    // Given
    final Map<Literal, BigDecimal> fromLiterals = ImmutableMap.of(new IntegerLiteral(5), new BigDecimal("5.00"), new LongLiteral(5), new BigDecimal("5.00"), new DoubleLiteral(5), new BigDecimal("5.00"), new DecimalLiteral(BigDecimal.TEN), new BigDecimal("10.00"), new DecimalLiteral(new BigDecimal("10.1")), new BigDecimal("10.10"));
    for (final Map.Entry<Literal, BigDecimal> entry : fromLiterals.entrySet()) {
        final Literal literal = entry.getKey();
        final BigDecimal expected = entry.getValue();
        // When
        final Expression expression = ImplicitlyCastResolver.resolve(literal, DECIMAL_5_2);
        // Then
        assertThat("Should cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, expression, instanceOf(DecimalLiteral.class));
        assertThat("Should cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, ((DecimalLiteral) expression).getValue(), is(expected));
    }
}
Also used : LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) Expression(io.confluent.ksql.execution.expression.tree.Expression) Literal(io.confluent.ksql.execution.expression.tree.Literal) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) BigDecimal(java.math.BigDecimal) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 19 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.

the class ImplicitlyCastResolverTest method shouldNotResolveNonDecimalTarget.

@Test
public void shouldNotResolveNonDecimalTarget() {
    // When
    final Expression expression = ImplicitlyCastResolver.resolve(new IntegerLiteral(5), SqlTypes.STRING);
    // Then
    assertThat(expression, instanceOf(IntegerLiteral.class));
    assertThat(((IntegerLiteral) expression).getValue(), is(5));
}
Also used : Expression(io.confluent.ksql.execution.expression.tree.Expression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 20 with Expression

use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.

the class LogicRewriterTest method assertExtractDisjuncts.

private void assertExtractDisjuncts(final String table, final String expressionStr, final String... expectedStrs) {
    Expression expression = getWhereExpression(table, expressionStr);
    List<Expression> disjuncts = LogicRewriter.extractDisjuncts(expression);
    assertThat(disjuncts.size(), is(expectedStrs.length));
    // When
    int i = 0;
    for (Expression e : disjuncts) {
        assertThat(e.toString(), is(expectedStrs[i++]));
    }
}
Also used : Expression(io.confluent.ksql.execution.expression.tree.Expression)

Aggregations

Expression (io.confluent.ksql.execution.expression.tree.Expression)343 Test (org.junit.Test)297 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)213 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)195 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)179 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)170 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)170 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)159 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)150 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)143 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)142 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)138 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)125 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)114 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)112 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)99 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)94 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)89 KsqlException (io.confluent.ksql.util.KsqlException)72 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)53