use of io.confluent.ksql.execution.expression.tree.InListExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowOnInAndComparisonExpression.
@Test
public void shouldThrowOnInAndComparisonExpression() {
// Given:
final Expression expression1 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
final Expression expression2 = new InPredicate(new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new InListExpression(ImmutableList.of(new IntegerLiteral(1), new IntegerLiteral(2))));
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, expression1, expression2);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("A comparison condition on the key column cannot be " + "combined with other comparisons"));
}
use of io.confluent.ksql.execution.expression.tree.InListExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValuesFromInExpression.
@Test
public void shouldExtractKeyValuesFromInExpression() {
// Given:
final Expression expression = new InPredicate(new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new InListExpression(ImmutableList.of(new IntegerLiteral(1), new IntegerLiteral(2))));
QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions);
// When:
final List<LookupConstraint> keys = filterNode.getLookupConstraints();
// Then:
assertThat(filterNode.isWindowed(), is(false));
assertThat(keys.size(), is(2));
final KeyConstraint keyConstraint0 = (KeyConstraint) keys.get(0);
assertThat(keyConstraint0.getKey(), is(GenericKey.genericKey(1)));
assertThat(keyConstraint0.getWindowBounds(), is(Optional.empty()));
final KeyConstraint keyConstraint1 = (KeyConstraint) keys.get(1);
assertThat(keyConstraint1.getKey(), is(GenericKey.genericKey(2)));
assertThat(keyConstraint1.getWindowBounds(), is(Optional.empty()));
}
use of io.confluent.ksql.execution.expression.tree.InListExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateInPredicate.
@Test
public void shouldEvaluateInPredicate() {
// Given:
final Expression in1 = new InPredicate(COL7, new InListExpression(ImmutableList.of(new IntegerLiteral(4), new IntegerLiteral(6), new IntegerLiteral(8))));
final Expression in2 = new InPredicate(COL1, new InListExpression(ImmutableList.of(new StringLiteral("a"), new StringLiteral("b"), new StringLiteral("c"))));
// When:
InterpretedExpression interpreter1 = interpreter(in1);
InterpretedExpression interpreter2 = interpreter(in2);
// Then:
assertThat(interpreter1.evaluate(make(7, 1)), is(false));
assertThat(interpreter1.evaluate(make(7, 6)), is(true));
assertThat(interpreter1.evaluate(make(7, 8)), is(true));
assertThat(interpreter1.evaluate(make(7, 10)), is(false));
assertThat(interpreter2.evaluate(make(1, "z")), is(false));
assertThat(interpreter2.evaluate(make(1, "a")), is(true));
assertThat(interpreter2.evaluate(make(1, "c")), is(true));
}
use of io.confluent.ksql.execution.expression.tree.InListExpression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteInListExpression.
@Test
public void shouldRewriteInListExpression() {
// Given:
final InPredicate inPredicate = parseExpression("1 IN (1, 2, 3)");
final InListExpression parsed = inPredicate.getValueList();
when(processor.apply(parsed.getValues().get(0), context)).thenReturn(expr1);
when(processor.apply(parsed.getValues().get(1), context)).thenReturn(expr2);
when(processor.apply(parsed.getValues().get(2), context)).thenReturn(expr3);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new InListExpression(parsed.getLocation(), ImmutableList.of(expr1, expr2, expr3))));
}
use of io.confluent.ksql.execution.expression.tree.InListExpression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteInListUsingPlugin.
@Test
public void shouldRewriteInListUsingPlugin() {
// Given:
final InPredicate inPredicate = parseExpression("1 IN (1, 2, 3)");
final InListExpression parsed = inPredicate.getValueList();
// When/Then:
shouldRewriteUsingPlugin(parsed);
}
Aggregations