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);
}
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));
}
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));
}
}
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));
}
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++]));
}
}
Aggregations