Search in sources :

Example 66 with IntegerLiteral

use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.

the class CoercionUtilTest method shouldCoerceToBigIntIfStringNumericTooWideForInt.

@Test
public void shouldCoerceToBigIntIfStringNumericTooWideForInt() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("1234567890000"));
    // 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(1234567890000L))));
}
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 67 with IntegerLiteral

use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.

the class CoercionUtilTest method shouldNotCoerceMapOfIncompatibleKeyLiterals.

@Test
public void shouldNotCoerceMapOfIncompatibleKeyLiterals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(289476))), new CreateMapExpression(ImmutableMap.of(new BooleanLiteral(false), new StringLiteral("123456789000"))));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
    // Then:
    assertThat(e.getMessage(), startsWith("operator does not exist: MAP<INTEGER, INTEGER> = MAP<BOOLEAN, STRING> (MAP(false:='123456789000'))"));
}
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) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 68 with IntegerLiteral

use of io.confluent.ksql.execution.expression.tree.IntegerLiteral 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 69 with IntegerLiteral

use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.

the class CoercionUtilTest method shouldNotCoerceMapWithDifferentKeyExpression.

@Test
public void shouldNotCoerceMapWithDifferentKeyExpression() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateMapExpression(ImmutableMap.of(new IntegerLiteral(10), new IntegerLiteral(10))), new CreateMapExpression(ImmutableMap.of(STRING_EXPRESSION, new IntegerLiteral(10))));
    // When:
    final Exception e = assertThrows(KsqlException.class, () -> CoercionUtil.coerceUserList(expressions, typeManager));
    // Then:
    assertThat(e.getMessage(), startsWith("operator does not exist: MAP<INTEGER, INTEGER> = MAP<STRING, INTEGER> (MAP(STR:=10))"));
}
Also used : CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) 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) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 70 with IntegerLiteral

use of io.confluent.ksql.execution.expression.tree.IntegerLiteral 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)

Aggregations

IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)150 Test (org.junit.Test)146 Expression (io.confluent.ksql.execution.expression.tree.Expression)111 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)85 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)81 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)66 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)62 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)61 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)61 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)60 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)46 KsqlException (io.confluent.ksql.util.KsqlException)46 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)45 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)42 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)38 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)38 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)30 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)24 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)23 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)23