Search in sources :

Example 6 with Result

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

the class CoercionUtilTest method shouldHandleEmpty.

@Test
public void shouldHandleEmpty() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of();
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.empty()));
    assertThat(result.expressions(), is(ImmutableList.of()));
}
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) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 7 with Result

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

the class CoercionUtilTest method shouldCoerceToDecimals.

@Test
public void shouldCoerceToDecimals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new LongLiteral(1234567890), new StringLiteral("\t -100.010 \t"), BIGINT_EXPRESSION, DECIMAL_EXPRESSION, INT_EXPRESSION);
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    final SqlDecimal decimalType = SqlTypes.decimal(22, 3);
    assertThat(result.commonType(), is(Optional.of(decimalType)));
    assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("10.000")), new DecimalLiteral(new BigDecimal("1234567890.000")), new DecimalLiteral(new BigDecimal("-100.010")), cast(BIGINT_EXPRESSION, decimalType), cast(DECIMAL_EXPRESSION, decimalType), cast(INT_EXPRESSION, decimalType))));
}
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) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) SqlDecimal(io.confluent.ksql.schema.ksql.types.SqlDecimal) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) BigDecimal(java.math.BigDecimal) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 8 with Result

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

the class CoercionUtilTest method shouldHandleSomeNulls.

@Test
public void shouldHandleSomeNulls() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new NullLiteral(), new IntegerLiteral(10), new NullLiteral(), new LongLiteral(20L), new NullLiteral());
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
    assertThat(result.expressions(), is(ImmutableList.of(new NullLiteral(), new LongLiteral(10), new NullLiteral(), new LongLiteral(20L), 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) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 9 with Result

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

the class CoercionUtilTest method shouldCoerceMapOfCompatibleLiterals.

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

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

the class CoercionUtilTest method shouldCoerceLambdaVariables.

@Test
public void shouldCoerceLambdaVariables() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(BIGINT_EXPRESSION, new LambdaVariable("X"), INT_EXPRESSION);
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager, Collections.singletonMap("X", SqlTypes.INTEGER));
    // Then:
    assertThat(result.commonType(), is(Optional.of(SqlTypes.BIGINT)));
    assertThat(result.expressions(), is(ImmutableList.of(BIGINT_EXPRESSION, cast(new LambdaVariable("X"), SqlTypes.BIGINT), cast(INT_EXPRESSION, SqlTypes.BIGINT))));
}
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) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) 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