use of io.confluent.ksql.execution.expression.tree.Expression 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()))));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowOnGTAndGTEComparisonsForSameBound.
@Test
public void shouldThrowOnGTAndGTEComparisonsForSameBound() {
// 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 windowEnd = new ComparisonExpression(Type.GREATER_THAN_OR_EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), new IntegerLiteral(3));
final Expression expressionA = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, expressionA, windowEnd);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, true, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("Duplicate `WINDOWSTART` bounds on: GREATER_THAN"));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowOnUsageOfWindowBoundOnNonwindowedTable.
@Test
public void shouldThrowOnUsageOfWindowBoundOnNonwindowedTable() {
// 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);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("Cannot use WINDOWSTART/WINDOWEND on non-windowed source."));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldRangeScanFromStringRangeComparison.
@Test
public void shouldRangeScanFromStringRangeComparison() {
// Given:
when(source.getSchema()).thenReturn(STRING_SCHEMA);
final Expression expression = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new StringLiteral("1"));
// Then:
expectRangeScan(expression, false);
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldSupportMultiRangeExpressionsUsingTableScan.
@Test
public void shouldSupportMultiRangeExpressionsUsingTableScan() {
// Given:
when(source.getSchema()).thenReturn(MULTI_KEY_SCHEMA);
final Expression expression1 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new IntegerLiteral(1));
final Expression expression2 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K2")), new IntegerLiteral(2));
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, expression1, expression2);
expectTableScan(expression, false);
}
Aggregations