use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToInts.
@Test
public void shouldCoerceToInts() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("\t -100 \t"), INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.INTEGER)));
assertThat(result.expressions(), is(ImmutableList.of(new IntegerLiteral(10), new IntegerLiteral(-100), INT_EXPRESSION)));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToBigInts.
@Test
public void shouldCoerceToBigInts() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new LongLiteral(1234567890), new StringLiteral("\t -100 \t"), BIGINT_EXPRESSION, INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
assertThat(result.expressions(), is(ImmutableList.of(new LongLiteral(10), new LongLiteral(1234567890), new LongLiteral(-100), BIGINT_EXPRESSION, cast(INT_EXPRESSION, SqlTypes.BIGINT))));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldCoerceToIntsToDecimals.
@Test
public void shouldCoerceToIntsToDecimals() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new DecimalLiteral(new BigDecimal("1.1")), new IntegerLiteral(10), INT_EXPRESSION);
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
final SqlDecimal decimalType = SqlTypes.decimal(11, 1);
assertThat(result.commonType(), is(Optional.of(decimalType)));
assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("1.1")), new DecimalLiteral(new BigDecimal("10.0")), cast(INT_EXPRESSION, decimalType))));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldDriveCoercionFromFirstNonNullExpression.
@Test
public void shouldDriveCoercionFromFirstNonNullExpression() {
// Given:
final ImmutableList<Expression> stringFirst = ImmutableList.of(new NullLiteral(), new StringLiteral("false"), new BooleanLiteral(true));
final ImmutableList<Expression> boolFirst = ImmutableList.of(new NullLiteral(), new BooleanLiteral(true), new StringLiteral("false"));
// When:
final Result stringResult = CoercionUtil.coerceUserList(stringFirst, typeManager);
final Result boolResult = CoercionUtil.coerceUserList(boolFirst, typeManager);
// Then:
assertThat(stringResult.commonType(), is(Optional.of(SqlTypes.STRING)));
assertThat(stringResult.expressions(), is(ImmutableList.of(new NullLiteral(), new StringLiteral("false"), new StringLiteral("true"))));
assertThat(boolResult.commonType(), is(Optional.of(SqlTypes.BOOLEAN)));
assertThat(boolResult.expressions(), is(ImmutableList.of(new NullLiteral(), new BooleanLiteral(true), new BooleanLiteral(false))));
}
use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.
the class CoercionUtilTest method shouldHandleOnlyNulls.
@Test
public void shouldHandleOnlyNulls() {
// Given:
final ImmutableList<Expression> expressions = ImmutableList.of(new NullLiteral(), new NullLiteral());
// When:
final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
// Then:
assertThat(result.commonType(), is(Optional.empty()));
assertThat(result.expressions(), is(ImmutableList.of(new NullLiteral(), new NullLiteral())));
}
Aggregations