use of io.confluent.ksql.execution.expression.tree.Cast 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.Cast in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToMap.
@Test
public void shouldEvaluateCastToMap() {
// Given:
final Expression cast1 = new Cast(new CreateMapExpression(ImmutableMap.of(new StringLiteral("1"), new StringLiteral("2"), new StringLiteral("3"), new StringLiteral("4"))), new Type(SqlTypes.map(SqlTypes.INTEGER, SqlTypes.INTEGER)));
final Expression cast2 = new Cast(new CreateMapExpression(ImmutableMap.of(new DoubleLiteral(2.5), new StringLiteral("2"), new DoubleLiteral(3.5), new StringLiteral("4"))), new Type(SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT)));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
// Then:
assertThat(interpreter1.evaluate(ROW), is(ImmutableMap.of(1, 2, 3, 4)));
assertThat(interpreter2.evaluate(ROW), is(ImmutableMap.of("2.5", 2L, "3.5", 4L)));
}
use of io.confluent.ksql.execution.expression.tree.Cast in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatCastToStruct.
@Test
public void shouldFormatCastToStruct() {
// Given:
final Cast cast = new Cast(new StringLiteral("foo"), new Type(SqlStruct.builder().field("field", SqlTypes.STRING).build()));
// When:
final String result = ExpressionFormatter.formatExpression(cast, FormatOptions.none());
// Then:
assertThat(result, equalTo("CAST('foo' AS STRUCT<`field` STRING>)"));
}
use of io.confluent.ksql.execution.expression.tree.Cast in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldCreateCorrectCastJavaExpression.
@Test
public void shouldCreateCorrectCastJavaExpression() {
// Given:
final Expression castBigintInteger = new Cast(COL0, new io.confluent.ksql.execution.expression.tree.Type(SqlPrimitiveType.of("INTEGER")));
// When:
final String actual = sqlToJavaVisitor.process(castBigintInteger);
// Then:
final String expected = CastEvaluator.generateCode("COL0", SqlTypes.BIGINT, SqlTypes.INTEGER, ksqlConfig);
assertThat(actual, is(expected));
}
use of io.confluent.ksql.execution.expression.tree.Cast in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToDate.
@Test
public void shouldEvaluateCastToDate() {
// Given:
final Expression cast1 = new Cast(new TimestampLiteral(Timestamp.from(Instant.ofEpochMilli(864000500))), new Type(SqlPrimitiveType.of("DATE")));
final Expression cast2 = new Cast(new StringLiteral("2017-11-13"), new Type(SqlPrimitiveType.of("DATE")));
final Expression cast3 = new Cast(new DateLiteral(new Date(864000000)), new Type(SqlPrimitiveType.of("DATE")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
// Then:
assertThat(interpreter1.evaluate(ROW), is(new Date(864000000)));
assertThat(interpreter2.evaluate(ROW), is(new Date(1510531200000L)));
assertThat(interpreter3.evaluate(ROW), is(new Date(864000000)));
}
Aggregations