Search in sources :

Example 11 with InPredicate

use of io.confluent.ksql.execution.expression.tree.InPredicate 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 12 with InPredicate

use of io.confluent.ksql.execution.expression.tree.InPredicate 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)

Aggregations

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