use of io.confluent.ksql.execution.expression.tree.ComparisonExpression 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)"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowMultiKeyExpressionsThatDontCoverAllKeys.
@Test
public void shouldThrowMultiKeyExpressionsThatDontCoverAllKeys() {
// Given:
when(source.getSchema()).thenReturn(MULTI_KEY_SCHEMA);
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), 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("Multi-column sources must specify every key in the WHERE clause. " + "Specified: [`K1`] Expected: [`K1` INTEGER KEY, `K2` INTEGER KEY]"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyFromNonEqualComparison.
@Test
public void shouldExtractKeyFromNonEqualComparison() {
// Given:
final Expression expression = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
final 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), is(instanceOf(NonKeyConstraint.class)));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueFromExpressionWithNoWindowBounds.
// We should refactor the WindowBounds class to encompass the functionality around
// extracting them from expressions instead of having them in WhereInfo
@Test
public void shouldExtractKeyValueFromExpressionWithNoWindowBounds() {
// 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, 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())));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldReturnKeyConstraintStringForOr.
@Test
public void shouldReturnKeyConstraintStringForOr() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("K1"), SqlTypes.STRING).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
when(source.getSchema()).thenReturn(schema);
final Expression keyExp1 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new StringLiteral("v1"));
final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new StringLiteral("v2"));
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(keys.size(), is(2));
assertThat(keys.get(0), instanceOf(KeyConstraint.class));
final KeyConstraint keyConstraint1 = (KeyConstraint) keys.get(0);
assertThat(keyConstraint1.getKey(), is(GenericKey.genericKey("v1")));
assertThat(keyConstraint1.getOperator(), is(KeyConstraint.ConstraintOperator.GREATER_THAN));
assertThat(keys.get(1), instanceOf(KeyConstraint.class));
final KeyConstraint keyConstraint2 = (KeyConstraint) keys.get(1);
assertThat(keyConstraint2.getKey(), is(GenericKey.genericKey("v2")));
assertThat(keyConstraint2.getOperator(), is(KeyConstraint.ConstraintOperator.EQUAL));
}
Aggregations