use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateSubscriptExpression.
@Test
public void shouldEvaluateSubscriptExpression() {
// Given:
final Expression expression1 = new SubscriptExpression(new CreateArrayExpression(ImmutableList.of(new StringLiteral("1"), new StringLiteral("2"))), new IntegerLiteral(1));
final Expression expression2 = new SubscriptExpression(new CreateMapExpression(ImmutableMap.of(new StringLiteral("a"), new LongLiteral(123), new StringLiteral("b"), new LongLiteral(456))), new StringLiteral("a"));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
// Then:
assertThat(interpreter1.evaluate(ROW), is("1"));
assertThat(interpreter2.evaluate(ROW), is(123L));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToDouble.
@Test
public void shouldEvaluateCastToDouble() {
// Given:
final Expression cast1 = new Cast(new LongLiteral(10L), new Type(SqlPrimitiveType.of("DOUBLE")));
final Expression cast2 = new Cast(new StringLiteral("1234.5"), new Type(SqlPrimitiveType.of("DOUBLE")));
final Expression cast3 = new Cast(new IntegerLiteral(12), new Type(SqlPrimitiveType.of("DOUBLE")));
final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("DOUBLE")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
InterpretedExpression interpreter4 = interpreter(cast4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(10d));
assertThat(interpreter2.evaluate(ROW), is(1234.5d));
assertThat(interpreter3.evaluate(ROW), is(12d));
assertThat(interpreter4.evaluate(ROW), is(4567.5d));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToArray.
@Test
public void shouldEvaluateCastToArray() {
// Given:
final Expression cast1 = new Cast(new CreateArrayExpression(ImmutableList.of(new StringLiteral("1"), new StringLiteral("2"))), new Type(SqlTypes.array(SqlTypes.INTEGER)));
final Expression cast2 = new Cast(new CreateArrayExpression(ImmutableList.of(new DoubleLiteral(2.5), new DoubleLiteral(3.6))), new Type(SqlTypes.array(SqlTypes.INTEGER)));
final Expression cast3 = new Cast(new CreateArrayExpression(ImmutableList.of(new DoubleLiteral(2.5), new DoubleLiteral(3.6))), new Type(SqlTypes.array(SqlTypes.STRING)));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
// Then:
assertThat(interpreter1.evaluate(ROW), is(ImmutableList.of(1, 2)));
assertThat(interpreter2.evaluate(ROW), is(ImmutableList.of(2, 3)));
assertThat(interpreter3.evaluate(ROW), is(ImmutableList.of("2.5", "3.6")));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateLikePredicate.
@Test
public void shouldEvaluateLikePredicate() {
// Given:
final Expression expression1 = new LikePredicate(new StringLiteral("catdog"), new StringLiteral("ca%og"), Optional.empty());
final Expression expression2 = new LikePredicate(new StringLiteral("cat%og"), new StringLiteral("cat\\%og"), Optional.empty());
final Expression expression3 = new LikePredicate(new StringLiteral("cat%og"), new StringLiteral("cat\\%og"), Optional.of('\\'));
// When:
InterpretedExpression interpreter1 = interpreter(expression1);
InterpretedExpression interpreter2 = interpreter(expression2);
InterpretedExpression interpreter3 = interpreter(expression3);
// Then:
assertThat(interpreter1.evaluate(ROW), is(true));
assertThat(interpreter2.evaluate(ROW), is(false));
assertThat(interpreter3.evaluate(ROW), is(true));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToDecimal.
@Test
public void shouldEvaluateCastToDecimal() {
// Given:
final Expression cast1 = new Cast(new LongLiteral(10L), new Type(SqlTypes.decimal(10, 1)));
final Expression cast2 = new Cast(new StringLiteral("1234.5"), new Type(SqlTypes.decimal(10, 1)));
final Expression cast3 = new Cast(new IntegerLiteral(12), new Type(SqlTypes.decimal(10, 1)));
final Expression cast4 = new Cast(new DoubleLiteral(4567.5), new Type(SqlTypes.decimal(10, 1)));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
InterpretedExpression interpreter4 = interpreter(cast4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(BigDecimal.valueOf(10L).setScale(1)));
assertThat(interpreter2.evaluate(ROW), is(BigDecimal.valueOf(1234.5d).setScale(1)));
assertThat(interpreter3.evaluate(ROW), is(BigDecimal.valueOf(12).setScale(1)));
assertThat(interpreter4.evaluate(ROW), is(BigDecimal.valueOf(4567.5d).setScale(1)));
}
Aggregations