use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class ImplicitlyCastResolverTest method shouldCastToDecimal.
@Test
public void shouldCastToDecimal() {
// Given
final Map<Literal, BigDecimal> fromLiterals = ImmutableMap.of(new IntegerLiteral(5), new BigDecimal("5.00"), new LongLiteral(5), new BigDecimal("5.00"), new DoubleLiteral(5), new BigDecimal("5.00"), new DecimalLiteral(BigDecimal.TEN), new BigDecimal("10.00"), new DecimalLiteral(new BigDecimal("10.1")), new BigDecimal("10.10"));
for (final Map.Entry<Literal, BigDecimal> entry : fromLiterals.entrySet()) {
final Literal literal = entry.getKey();
final BigDecimal expected = entry.getValue();
// When
final Expression expression = ImplicitlyCastResolver.resolve(literal, DECIMAL_5_2);
// Then
assertThat("Should cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, expression, instanceOf(DecimalLiteral.class));
assertThat("Should cast " + literal.getClass().getSimpleName() + " to " + DECIMAL_5_2, ((DecimalLiteral) expression).getValue(), is(expected));
}
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class ImplicitlyCastResolverTest method shouldNotResolveNonDecimalTarget.
@Test
public void shouldNotResolveNonDecimalTarget() {
// When
final Expression expression = ImplicitlyCastResolver.resolve(new IntegerLiteral(5), SqlTypes.STRING);
// Then
assertThat(expression, instanceOf(IntegerLiteral.class));
assertThat(((IntegerLiteral) expression).getValue(), is(5));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithEQWindowEnd.
@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithEQWindowEnd() {
// Given:
final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
final Expression windowStart = new ComparisonExpression(Type.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(Range.singleton(Instant.ofEpochMilli(2)), null, null)))));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueFromExpressionEquals_multipleDisjuncts.
@Test
public void shouldExtractKeyValueFromExpressionEquals_multipleDisjuncts() {
// Given:
final Expression keyExp1 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), 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);
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(2));
final KeyConstraint keyConstraint1 = (KeyConstraint) keys.get(0);
assertThat(keyConstraint1.getKey(), is(GenericKey.genericKey(1)));
assertThat(keyConstraint1.getWindowBounds(), is(Optional.empty()));
final KeyConstraint keyConstraint2 = (KeyConstraint) keys.get(1);
assertThat(keyConstraint2.getKey(), is(GenericKey.genericKey(2)));
assertThat(keyConstraint2.getWindowBounds(), is(Optional.empty()));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithLTWindowEnd.
@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithLTWindowEnd() {
// 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("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, Range.upTo(Instant.ofEpochMilli(2), BoundType.OPEN), null)))));
}
Aggregations