Search in sources :

Example 56 with IntegerLiteral

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

the class CoercionUtilTest method shouldCoerceStructOfCompatibleLiterals.

@Test
public void shouldCoerceStructOfCompatibleLiterals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), new CreateStructExpression(ImmutableList.of(new Field("a", new StringLiteral("123456789000")))));
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    final SqlStruct sqlStruct = SqlTypes.struct().field("a", SqlTypes.BIGINT).build();
    assertThat(result.commonType(), is(Optional.of(sqlStruct)));
    assertThat(result.expressions(), is(ImmutableList.of(cast(new CreateStructExpression(ImmutableList.of(new Field("a", new IntegerLiteral(10)))), sqlStruct), cast(new CreateStructExpression(ImmutableList.of(new Field("a", new StringLiteral("123456789000")))), sqlStruct))));
}
Also used : Field(io.confluent.ksql.execution.expression.tree.CreateStructExpression.Field) SqlStruct(io.confluent.ksql.schema.ksql.types.SqlStruct) 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) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Result(io.confluent.ksql.execution.util.CoercionUtil.Result) Test(org.junit.Test)

Example 57 with IntegerLiteral

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

the class CoercionUtilTest method shouldNotCoerceArrayWithDifferentExpression.

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

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

the class CoercionUtilTest method shouldCoerceStringNumericWithDecimalPointToDecimals.

@Test
public void shouldCoerceStringNumericWithDecimalPointToDecimals() {
    // Given:
    final ImmutableList<Expression> expressions = ImmutableList.of(new IntegerLiteral(10), new StringLiteral("1.0"));
    // When:
    final Result result = CoercionUtil.coerceUserList(expressions, typeManager);
    // Then:
    assertThat(result.commonType(), is(Optional.of(SqlTypes.decimal(11, 1))));
    assertThat(result.expressions(), is(ImmutableList.of(new DecimalLiteral(new BigDecimal("10.0")), new DecimalLiteral(new BigDecimal("1.0")))));
}
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)

Example 59 with IntegerLiteral

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

the class ExpressionTypeManagerTest method shouldEvaluateAnyNumberOfArgumentLambda.

@Test
public void shouldEvaluateAnyNumberOfArgumentLambda() {
    // Given:
    givenUdfWithNameAndReturnType("TRANSFORM", SqlTypes.STRING);
    when(function.parameters()).thenReturn(ImmutableList.of(ArrayType.of(DoubleType.INSTANCE), StringType.INSTANCE, MapType.of(LongType.INSTANCE, DoubleType.INSTANCE), LambdaType.of(ImmutableList.of(DoubleType.INSTANCE, StringType.INSTANCE, LongType.INSTANCE, DoubleType.INSTANCE), StringType.INSTANCE)));
    final Expression expression = new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(ARRAYCOL, new StringLiteral("Q"), MAPCOL, new LambdaFunctionCall(ImmutableList.of("A", "B", "C", "D"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("C"), new IntegerLiteral(5)))));
    // When:
    final SqlType exprType = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    assertThat(exprType, is(SqlTypes.STRING));
    verify(udfFactory).getFunction(ImmutableList.of(SqlArgument.of(SqlTypes.array(SqlTypes.DOUBLE)), SqlArgument.of(SqlTypes.STRING), SqlArgument.of(SqlTypes.map(SqlTypes.BIGINT, SqlTypes.DOUBLE)), SqlArgument.of(SqlLambda.of(4))));
    verify(function).getReturnType(ImmutableList.of(SqlArgument.of(SqlTypes.array(SqlTypes.DOUBLE)), SqlArgument.of(SqlTypes.STRING), SqlArgument.of(SqlTypes.map(SqlTypes.BIGINT, SqlTypes.DOUBLE)), SqlArgument.of(SqlLambdaResolved.of(ImmutableList.of(SqlTypes.DOUBLE, SqlTypes.STRING, SqlTypes.BIGINT, SqlTypes.DOUBLE), SqlTypes.BIGINT))));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 60 with IntegerLiteral

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

the class ExpressionTypeManagerTest method shouldHandleMultipleLambdasInSameFunctionCallWithDifferentVariableNames.

@Test
public void shouldHandleMultipleLambdasInSameFunctionCallWithDifferentVariableNames() {
    // Given:
    givenUdfWithNameAndReturnType("TRANSFORM", SqlTypes.INTEGER);
    when(function.parameters()).thenReturn(ImmutableList.of(MapType.of(LongType.INSTANCE, DoubleType.INSTANCE), IntegerType.INSTANCE, LambdaType.of(ImmutableList.of(DoubleType.INSTANCE, DoubleType.INSTANCE), StringType.INSTANCE), LambdaType.of(ImmutableList.of(DoubleType.INSTANCE, DoubleType.INSTANCE), StringType.INSTANCE)));
    final Expression expression = new ArithmeticBinaryExpression(Operator.ADD, new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(MAPCOL, new IntegerLiteral(0), new LambdaFunctionCall(ImmutableList.of("A", "B"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("A"), new LambdaVariable("B"))), new LambdaFunctionCall(ImmutableList.of("K", "V"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("K"), new LambdaVariable("V"))))), new IntegerLiteral(5));
    // When:
    final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
    assertThat(result, is(SqlTypes.INTEGER));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) 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