Search in sources :

Example 11 with Result

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)));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 12 with Result

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))));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 13 with Result

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))));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) BigDecimal(java.math.BigDecimal) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 14 with Result

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))));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 15 with Result

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())));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Aggregations

CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)17 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)17 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)17 Expression (io.confluent.ksql.execution.expression.tree.Expression)17 Result (io.confluent.ksql.execution.util.CoercionUtil.Result)17 Test (org.junit.Test)17 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)12 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)12 LongLiteral (io.confluent.ksql.execution.expression.tree.LongLiteral)5 DecimalLiteral (io.confluent.ksql.execution.expression.tree.DecimalLiteral)4 BigDecimal (java.math.BigDecimal)4 NullLiteral (io.confluent.ksql.execution.expression.tree.NullLiteral)3 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)2 SqlDecimal (io.confluent.ksql.schema.ksql.types.SqlDecimal)2 Field (io.confluent.ksql.execution.expression.tree.CreateStructExpression.Field)1 DoubleLiteral (io.confluent.ksql.execution.expression.tree.DoubleLiteral)1 LambdaVariable (io.confluent.ksql.execution.expression.tree.LambdaVariable)1 SqlStruct (io.confluent.ksql.schema.ksql.types.SqlStruct)1