Search in sources :

Example 6 with InListExpression

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"));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) KsqlException(io.confluent.ksql.util.KsqlException) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 7 with InListExpression

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()));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 8 with InListExpression

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));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 9 with InListExpression

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))));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) Test(org.junit.Test)

Example 10 with InListExpression

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);
}
Also used : InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) Test(org.junit.Test)

Aggregations

InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)10 InPredicate (io.confluent.ksql.execution.expression.tree.InPredicate)10 Test (org.junit.Test)9 Expression (io.confluent.ksql.execution.expression.tree.Expression)8 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)7 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)5 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)5 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)5 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)5 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)5 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)5 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)5 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)5 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)4 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)4 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)4 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)3 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)3 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)3 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)2