use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowOnMultiColKeySchema.
@Test
public void shouldThrowOnMultiColKeySchema() {
// Given:
final LogicalSchema multiSchema = LogicalSchema.builder().keyColumn(ColumnName.of("K"), SqlTypes.INTEGER).keyColumn(ColumnName.of("K2"), SqlTypes.INTEGER).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new ArithmeticUnaryExpression(Optional.empty(), Sign.MINUS, new IntegerLiteral(1)));
when(source.getSchema()).thenReturn(multiSchema);
// 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: [`K`] Expected: [`K` INTEGER KEY, `K2` INTEGER KEY]."));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTEWindowEnd.
@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTEWindowEnd() {
// 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("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.CLOSED))))));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowOnNonKeyCol.
@Test
public void shouldThrowOnNonKeyCol() {
// Given:
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("COL0")), new StringLiteral("abc"));
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("WHERE clause missing key column for disjunct: " + "(COL0 = 'abc')"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithBothWindowBounds.
@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithBothWindowBounds() {
// 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.LESS_THAN_OR_EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWEND")), new IntegerLiteral(3));
final Expression expressionA = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, expressionA, windowEnd);
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(null, Range.upTo(Instant.ofEpochMilli(3), BoundType.CLOSED), null)))));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateComparisons_decimal.
@Test
public void shouldEvaluateComparisons_decimal() {
// Given:
final Expression expression1 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL8, new DecimalLiteral(new BigDecimal("1.2")));
final Expression expression2 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL8, new DecimalLiteral(new BigDecimal("5.1")));
final Expression expression3 = new ComparisonExpression(ComparisonExpression.Type.EQUAL, COL8, new DecimalLiteral(new BigDecimal("10.4")));
final Expression expression4 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL8, new IntegerLiteral(5));
final Expression expression5 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL8, new DoubleLiteral(6.5));
final Expression expression6 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL8, new LongLiteral(10L));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
InterpretedExpression interpreter4 = interpreter(expression4);
InterpretedExpression interpreter5 = interpreter(expression5);
InterpretedExpression interpreter6 = interpreter(expression6);
// Then:
assertThat(interpreter1.evaluate(make(8, new BigDecimal("3.4"))), is(true));
assertThat(interpreter1.evaluate(make(8, new BigDecimal("1.1"))), is(false));
assertThat(interpreter2.evaluate(make(8, new BigDecimal("4.9"))), is(true));
assertThat(interpreter2.evaluate(make(8, new BigDecimal("5.2"))), is(false));
assertThat(interpreter3.evaluate(make(8, new BigDecimal("10.4"))), is(true));
assertThat(interpreter3.evaluate(make(8, new BigDecimal("10.5"))), is(false));
assertThat(interpreter4.evaluate(make(8, new BigDecimal("6.5"))), is(true));
assertThat(interpreter4.evaluate(make(8, new BigDecimal("4.5"))), is(false));
assertThat(interpreter5.evaluate(make(8, new BigDecimal("5.5"))), is(true));
assertThat(interpreter5.evaluate(make(8, new BigDecimal("7.5"))), is(false));
assertThat(interpreter6.evaluate(make(8, new BigDecimal("7"))), is(true));
assertThat(interpreter6.evaluate(make(8, new BigDecimal("19.567"))), is(false));
}
Aggregations