use of io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression 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"));
}
use of io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTEWindowStart.
@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTEWindowStart() {
// Given:
final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
final Expression windowStart = new ComparisonExpression(Type.GREATER_THAN_OR_EQUAL, 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.CLOSED)), new WindowRange()))));
}
use of io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression 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.LogicalBinaryExpression 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()))));
}
use of io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowKeyExpressionThatDoestCoverKey_multipleDisjuncts.
@Test
public void shouldThrowKeyExpressionThatDoestCoverKey_multipleDisjuncts() {
// Given:
when(source.getSchema()).thenReturn(INPUT_SCHEMA);
final Expression keyExp1 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), 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);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, true, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("WHERE clause missing key column for disjunct: " + "(WINDOWSTART = 1)"));
}
Aggregations