use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateStruct.
@Test
public void shouldEvaluateStruct() {
// Given:
final Expression expression1 = new CreateStructExpression(ImmutableList.of(new Field("A", new IntegerLiteral(10)), new Field("B", new StringLiteral("abc"))));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
// Then:
assertThat(interpreter1.evaluate(ROW), is(new Struct(SchemaBuilder.struct().optional().field("A", SchemaBuilder.int32().optional().build()).field("B", SchemaBuilder.string().optional().build()).build()).put("A", 10).put("B", "abc")));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToBytes.
@Test
public void shouldEvaluateCastToBytes() {
// Given:
final Expression cast1 = new Cast(new BytesLiteral(ByteBuffer.wrap(new byte[] { 123 })), new Type(SqlPrimitiveType.of("BYTES")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
// Then:
assertThat(interpreter1.evaluate(ROW), is(ByteBuffer.wrap(new byte[] { 123 })));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToTime.
@Test
public void shouldEvaluateCastToTime() {
// Given:
final Expression cast1 = new Cast(new TimestampLiteral(Timestamp.from(Instant.ofEpochMilli(1000))), new Type(SqlPrimitiveType.of("TIME")));
final Expression cast2 = new Cast(new StringLiteral("23:59:58"), new Type(SqlPrimitiveType.of("TIME")));
final Expression cast3 = new Cast(new TimeLiteral(new Time(1000)), new Type(SqlPrimitiveType.of("TIME")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
// Then:
assertThat(interpreter1.evaluate(ROW), is(new Time(1000L)));
assertThat(interpreter2.evaluate(ROW), is(new Time(86398000)));
assertThat(interpreter3.evaluate(ROW), is(new Time(1000L)));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateComparisons_double.
@Test
public void shouldEvaluateComparisons_double() {
// Given:
final Expression expression1 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, COL3, new DoubleLiteral(-10.0));
final Expression expression2 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL3, new DoubleLiteral(10));
final Expression expression3 = new ComparisonExpression(ComparisonExpression.Type.EQUAL, COL3, new DoubleLiteral(6.5));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
// Then:
assertThat(interpreter1.evaluate(make(3, 5d)), is(true));
assertThat(interpreter1.evaluate(make(3, -20d)), is(false));
assertThat(interpreter2.evaluate(make(3, 5d)), is(true));
assertThat(interpreter2.evaluate(make(3, 20d)), is(false));
assertThat(interpreter3.evaluate(make(3, 6.5d)), is(true));
assertThat(interpreter3.evaluate(make(3, 8.5d)), is(false));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateComparisons_bytes.
@Test
public void shouldEvaluateComparisons_bytes() {
// Given:
final Expression expression1 = new ComparisonExpression(ComparisonExpression.Type.GREATER_THAN, BYTESCOL, new BytesLiteral(ByteBuffer.wrap(new byte[] { 123 })));
final Expression expression2 = new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, BYTESCOL, new BytesLiteral(ByteBuffer.wrap(new byte[] { 123 })));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
// Then:
assertThat(interpreter1.evaluate(make(14, ByteBuffer.wrap(new byte[] { 123 }))), is(false));
assertThat(interpreter2.evaluate(make(14, ByteBuffer.wrap(new byte[] { 110 }))), is(true));
}
Aggregations