use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldThrowIfNonConvertibleType.
@Test
public void shouldThrowIfNonConvertibleType() {
// Given:
final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new StringLiteral("foo"));
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
// Then:
assertThat(e.getMessage(), containsString("'foo' can not be converted to the type of the key column: K INTEGER KEY"));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldReturnKeyConstraintString.
@Test
public void shouldReturnKeyConstraintString() {
// Given:
when(plannerOptions.getTableScansEnabled()).thenReturn(true);
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.AND, 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(1));
assertThat(keys.get(0), instanceOf(KeyConstraint.class));
final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
assertThat(keyConstraint.getKey(), is(GenericKey.genericKey("v2")));
assertThat(keyConstraint.getOperator(), is(KeyConstraint.ConstraintOperator.EQUAL));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral 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.StringLiteral 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.StringLiteral 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')"));
}
Aggregations