use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueFromLiteralEquals.
@Test
public void shouldExtractKeyValueFromLiteralEquals() {
// Given:
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
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(1));
final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
assertThat(keyConstraint.getKey(), is(GenericKey.genericKey(1)));
assertThat(keyConstraint.getWindowBounds(), is(Optional.empty()));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractMultiColKeySchema.
@Test
public void shouldExtractMultiColKeySchema() {
// Given:
final LogicalSchema multiSchema = LogicalSchema.builder().keyColumn(ColumnName.of("K1"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K2"), SqlTypes.INTEGER).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
final Expression keyExp1 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new IntegerLiteral(1));
final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K2")), new IntegerLiteral(3));
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp1, keyExp2);
when(source.getSchema()).thenReturn(multiSchema);
QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions);
// When:
final List<LookupConstraint> keys = filterNode.getLookupConstraints();
// Then:
assertThat(keys.size(), is(1));
assertThat(keys.get(0), instanceOf(KeyConstraint.class));
final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
assertThat(keyConstraint.getKey(), is(GenericKey.genericKey(1, 3)));
assertThat(keyConstraint.getOperator(), is(KeyConstraint.ConstraintOperator.EQUAL));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldTableScanFromIntRangeComparison.
@SuppressWarnings("unchecked")
@Test
public void shouldTableScanFromIntRangeComparison() {
// Given:
final Expression expression = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
// Then:
expectTableScan(expression, false);
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowIfComparisonOnNonKey.
@Test
public void shouldThrowIfComparisonOnNonKey() {
// Given:
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("C1")), new IntegerLiteral(1));
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("Bound on non-existent column `C1`."));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithLTWindowStart.
@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithLTWindowStart() {
// 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("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, Range.upTo(Instant.ofEpochMilli(2), BoundType.OPEN), null), new WindowRange()))));
}
Aggregations