Search in sources :

Example 16 with Result

use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.

the class CoercionUtilTest method shouldCoerceArrayOfCompatibleLiterals.

@Test
public void shouldCoerceArrayOfCompatibleLiterals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateArrayExpression(ImmutableList.of(new StringLiteral("123456789000"), new StringLiteral("22"), new StringLiteral("\t -100 \t"))));
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.of(SqlTypes.array(SqlTypes.BIGINT))));
    assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateArrayExpression(ImmutableList.of(new IntegerLiteral(10), new IntegerLiteral(289476))), SqlTypes.array(SqlTypes.BIGINT)), cast(new CreateArrayExpression(ImmutableList.of(new StringLiteral("123456789000"), new StringLiteral("22"), new StringLiteral("\t -100 \t"))), SqlTypes.array(SqlTypes.BIGINT)))));
}
Also used : CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) 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 17 with Result

use of io.confluent.ksql.execution.util.CoercionUtil.Result in project ksql by confluentinc.

the class CoercionUtilTest method shouldCoerceStringNumericWithENotationToDecimals.

@Test
public void shouldCoerceStringNumericWithENotationToDecimals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("1e3"));
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.of(SqlTypes.decimal(10, 0))));
    assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("10")), new DecimalLiteral(new BigDecimal("1000")))));
}
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) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) BigDecimal(java.math.BigDecimal) 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