Search in sources :

Example 1 with WindowBounds

use of io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds 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 WindowBounds

use of io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds 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 3 with WindowBounds

use of io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBountsFromExpressionWithGTWindowStart.

@Test
public void shouldExtractKeyValueAndWindowBountsFromExpressionWithGTWindowStart() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), 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(null, null, Range.downTo(Instant.ofEpochMilli(2), BoundType.OPEN)), new WindowRange()))));
}
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 4 with WindowBounds

use of io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTWindowEnd.

@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTWindowEnd() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.GREATER_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, null, Range.downTo(Instant.ofEpochMilli(2), BoundType.OPEN))))));
}
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 WindowBounds

use of io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds in project ksql by confluentinc.

the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTWindowStartText.

@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTWindowStartText() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), new StringLiteral("2020-01-01"));
    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(null, null, Range.downTo(Instant.ofEpochMilli(1577836800_000L), BoundType.OPEN)), new WindowRange()))));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) 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)

Aggregations

ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)12 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)12 Expression (io.confluent.ksql.execution.expression.tree.Expression)12 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)12 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)12 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)12 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)12 WindowBounds (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds)12 Test (org.junit.Test)12 WindowRange (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange)11 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)1