use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatInPredicate.
@Test
public void shouldFormatInPredicate() {
final InPredicate predicate = new InPredicate(new StringLiteral("foo"), new InListExpression(ImmutableList.of(new StringLiteral("a"))));
assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('foo' IN ('a'))"));
}
use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteInPredicate.
@Test
public void shouldRewriteInPredicate() {
// Given:
final InPredicate parsed = parseExpression("1 IN (1, 2, 3)");
when(processor.apply(parsed.getValue(), context)).thenReturn(expr1);
when(processor.apply(parsed.getValueList(), context)).thenReturn(inList);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new InPredicate(parsed.getLocation(), expr1, inList)));
}
use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.
the class ExpressionTypeManagerTest method shouldEvaluateBooleanSchemaForInExpression.
@Test
public void shouldEvaluateBooleanSchemaForInExpression() {
final Expression expression = new InPredicate(TestExpressions.COL0, new InListExpression(ImmutableList.of(new StringLiteral("key1"))));
final SqlType exprType0 = expressionTypeManager.getExpressionSqlType(expression);
assertThat(exprType0, is(SqlTypes.BOOLEAN));
}
use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.
the class InListEvaluator method preprocess.
/**
* Preprocess the list of possible expression, ensuring compatible types, performing literal
* coercion and removing null literals (which can never match).
*
* @param predicate The predicate to process
* @param typeManager the type manager for the predicate
* @param lambdaTypeMapping mapping of lambda variables to type
* @return {@code predicate} after processing.
*/
public static InPredicate preprocess(final InPredicate predicate, final ExpressionTypeManager typeManager, final Map<String, SqlType> lambdaTypeMapping) {
final List<Expression> nonNull = ImmutableList.<Expression>builder().add(predicate.getValue()).addAll(predicate.getValueList().getValues().stream().filter(e -> !(e instanceof NullLiteral)).collect(Collectors.toList())).build();
final List<Expression> coerced = CoercionUtil.coerceUserList(nonNull, typeManager, lambdaTypeMapping).expressions();
return new InPredicate(predicate.getLocation(), coerced.get(0), new InListExpression(predicate.getValueList().getLocation(), coerced.subList(1, coerced.size())));
}
use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForInPredicate.
@Test
public void shouldGenerateCorrectCodeForInPredicate() {
// Given:
final Expression expression = new InPredicate(COL0, new InListExpression(ImmutableList.of(new IntegerLiteral(1), new IntegerLiteral(2))));
// When:
final String java = sqlToJavaVisitor.process(expression);
// Then:
assertThat(java, is("InListEvaluator.matches(COL0,1L,2L)"));
}
Aggregations