use of io.confluent.ksql.execution.expression.tree.Type 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.Type 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.Type in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatMap.
@Test
public void shouldFormatMap() {
final SqlMap map = SqlTypes.map(SqlTypes.INTEGER, SqlTypes.BIGINT);
assertThat(ExpressionFormatter.formatExpression(new Type(map)), equalTo("MAP<INTEGER, BIGINT>"));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatArray.
@Test
public void shouldFormatArray() {
final SqlArray array = SqlTypes.array(SqlTypes.BOOLEAN);
assertThat(ExpressionFormatter.formatExpression(new Type(array)), equalTo("ARRAY<BOOLEAN>"));
}
use of io.confluent.ksql.execution.expression.tree.Type 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>)"));
}
Aggregations