Search in sources :

Example 1 with ComparisonExpression

use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithEQWindowEnd.

@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithEQWindowEnd() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWEND")), new IntegerLiteral(2));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
    QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, true, plannerOptions);
    // When:
    final List<LookupConstraint> keys = filterNode.getLookupConstraints();
    // Then:
    assertThat(filterNode.isWindowed(), is(true));
    assertThat(keys.size(), is(1));
    final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
    assertThat(keyConstraint.getKey(), is(GenericKey.genericKey(1)));
    assertThat(keyConstraint.getWindowBounds(), is(Optional.of(new WindowBounds(new WindowRange(), new WindowRange(Range.singleton(Instant.ofEpochMilli(2)), null, null)))));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) WindowBounds(io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds) 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) WindowRange(io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 2 with ComparisonExpression

use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldThrowIfNonConvertibleType.

@Test
public void shouldThrowIfNonConvertibleType() {
    // Given:
    final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new StringLiteral("foo"));
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("'foo' can not be converted to the type of the key column: K INTEGER KEY"));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) 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) KsqlException(io.confluent.ksql.util.KsqlException) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 3 with ComparisonExpression

use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldExtractKeyValueFromExpressionEquals_multipleDisjuncts.

@Test
public void shouldExtractKeyValueFromExpressionEquals_multipleDisjuncts() {
    // Given:
    final Expression keyExp1 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(2));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, keyExp1, keyExp2);
    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 keyConstraint1 = (KeyConstraint) keys.get(0);
    assertThat(keyConstraint1.getKey(), is(GenericKey.genericKey(1)));
    assertThat(keyConstraint1.getWindowBounds(), is(Optional.empty()));
    final KeyConstraint keyConstraint2 = (KeyConstraint) keys.get(1);
    assertThat(keyConstraint2.getKey(), is(GenericKey.genericKey(2)));
    assertThat(keyConstraint2.getWindowBounds(), is(Optional.empty()));
}
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) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 4 with ComparisonExpression

use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithLTWindowEnd.

@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithLTWindowEnd() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.LESS_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWEND")), new IntegerLiteral(2));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
    QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, true, plannerOptions);
    // When:
    final List<LookupConstraint> keys = filterNode.getLookupConstraints();
    // Then:
    assertThat(filterNode.isWindowed(), is(true));
    assertThat(keys.size(), is(1));
    final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
    assertThat(keyConstraint.getKey(), is(GenericKey.genericKey(1)));
    assertThat(keyConstraint.getWindowBounds(), is(Optional.of(new WindowBounds(new WindowRange(), new WindowRange(null, Range.upTo(Instant.ofEpochMilli(2), BoundType.OPEN), null)))));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) WindowBounds(io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds) 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) WindowRange(io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 5 with ComparisonExpression

use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldThrowOnMultipleKeyExpressions.

@Test
public void shouldThrowOnMultipleKeyExpressions() {
    // Given:
    final Expression expression1 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression expression2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), 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) 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)

Aggregations

ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)102 Test (org.junit.Test)100 Expression (io.confluent.ksql.execution.expression.tree.Expression)72 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)67 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)65 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)60 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)60 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)55 KsqlException (io.confluent.ksql.util.KsqlException)26 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)25 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)19 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)19 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)19 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)19 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)19 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)19 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)14 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)13 WindowBounds (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds)12