use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class CommandFactoriesTest method shouldCreateCommandForRegisterType.
@Test
public void shouldCreateCommandForRegisterType() {
// Given:
final RegisterType ddlStatement = new RegisterType(Optional.empty(), "alias", new Type(SqlStruct.builder().field("foo", SqlPrimitiveType.of(SqlBaseType.STRING)).build()), true);
// When:
final DdlCommand result = commandFactories.create(sqlExpression, ddlStatement, SessionConfig.of(ksqlConfig, emptyMap()));
// Then:
assertThat(result, is(registerTypeCommand));
verify(registerTypeFactory).create(ddlStatement);
}
use of io.confluent.ksql.execution.expression.tree.Type 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)));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToTimestamp.
@Test
public void shouldEvaluateCastToTimestamp() {
// Given:
final Expression cast1 = new Cast(new TimestampLiteral(Timestamp.from(Instant.ofEpochMilli(1000))), new Type(SqlPrimitiveType.of("TIMESTAMP")));
final Expression cast2 = new Cast(new StringLiteral("2017-11-13T23:59:58"), new Type(SqlPrimitiveType.of("TIMESTAMP")));
final Expression cast3 = new Cast(new DateLiteral(new Date(864000000)), new Type(SqlPrimitiveType.of("TIMESTAMP")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
// Then:
assertThat(interpreter1.evaluate(ROW), is(new Timestamp(1000L)));
assertThat(interpreter2.evaluate(ROW), is(new Timestamp(1510617598000L)));
assertThat(interpreter3.evaluate(ROW), is(new Timestamp(864000000)));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToBigint.
@Test
public void shouldEvaluateCastToBigint() {
// Given:
final Expression cast1 = new Cast(new IntegerLiteral(10), new Type(SqlPrimitiveType.of("BIGINT")));
final Expression cast2 = new Cast(new StringLiteral("1234"), new Type(SqlPrimitiveType.of("BIGINT")));
final Expression cast3 = new Cast(new DoubleLiteral(12.5), new Type(SqlPrimitiveType.of("BIGINT")));
final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("BIGINT")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
InterpretedExpression interpreter4 = interpreter(cast4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(10L));
assertThat(interpreter2.evaluate(ROW), is(1234L));
assertThat(interpreter3.evaluate(ROW), is(12L));
assertThat(interpreter4.evaluate(ROW), is(4567L));
}
use of io.confluent.ksql.execution.expression.tree.Type in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToInteger.
@Test
public void shouldEvaluateCastToInteger() {
// Given:
final Expression cast1 = new Cast(new LongLiteral(10L), new Type(SqlPrimitiveType.of("INTEGER")));
final Expression cast2 = new Cast(new StringLiteral("1234"), new Type(SqlPrimitiveType.of("INTEGER")));
final Expression cast3 = new Cast(new DoubleLiteral(12.5), new Type(SqlPrimitiveType.of("INTEGER")));
final Expression cast4 = new Cast(new DecimalLiteral(new BigDecimal("4567.5")), new Type(SqlPrimitiveType.of("INTEGER")));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
InterpretedExpression interpreter3 = interpreter(cast3);
InterpretedExpression interpreter4 = interpreter(cast4);
// Then:
assertThat(interpreter1.evaluate(ROW), is(10));
assertThat(interpreter2.evaluate(ROW), is(1234));
assertThat(interpreter3.evaluate(ROW), is(12));
assertThat(interpreter4.evaluate(ROW), is(4567));
}
Aggregations