Search in sources :

Example 96 with IntegerLiteral

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

Example 97 with IntegerLiteral

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

the class ExpressionTypeManagerTest method shouldReturnBooleanForInPredicate.

@Test
public void shouldReturnBooleanForInPredicate() {
    // Given:
    final Expression expression = new InPredicate(TestExpressions.COL0, new InListExpression(ImmutableList.of(new IntegerLiteral(1), new IntegerLiteral(2))));
    // When:
    final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    assertThat(result, is(SqlTypes.BOOLEAN));
}
Also used : 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) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 98 with IntegerLiteral

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

the class ExpressionTypeManagerTest method shouldFailToEvaluateLambdaWithMismatchedArgumentNumber.

@Test
public void shouldFailToEvaluateLambdaWithMismatchedArgumentNumber() {
    // Given:
    givenUdfWithNameAndReturnType("TRANSFORM", SqlTypes.DOUBLE);
    when(function.parameters()).thenReturn(ImmutableList.of(ArrayType.of(DoubleType.INSTANCE), LambdaType.of(ImmutableList.of(DoubleType.INSTANCE), StringType.INSTANCE)));
    final Expression expression = new FunctionCall(FunctionName.of("TRANSFORM"), ImmutableList.of(ARRAYCOL, new LambdaFunctionCall(ImmutableList.of("X", "Y"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("X"), new IntegerLiteral(5)))));
    // When:
    final Exception e = assertThrows(Exception.class, () -> expressionTypeManager.getExpressionSqlType(expression));
    // Then:
    assertThat(e.getMessage(), Matchers.containsString("Was expecting 1 arguments but found 2, [X, Y]. Check your lambda statement."));
}
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) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 99 with IntegerLiteral

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

the class ExpressionTypeManagerTest method shouldGetCorrectSchemaForSearchedCaseWhenStruct.

@Test
public void shouldGetCorrectSchemaForSearchedCaseWhenStruct() {
    // Given:
    final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(Type.EQUAL, TestExpressions.COL0, new IntegerLiteral(10)), ADDRESS)), Optional.empty());
    // When:
    final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    final SqlType sqlType = SCHEMA.findColumn(ADDRESS.getColumnName()).get().type();
    assertThat(result, is(sqlType));
}
Also used : ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) 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) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 100 with IntegerLiteral

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

the class ExpressionTypeManagerTest method shouldEvaluateTypeForStructDereferenceInArray.

@Test
public void shouldEvaluateTypeForStructDereferenceInArray() {
    // Given:
    final SqlStruct inner = SqlTypes.struct().field("IN0", SqlTypes.INTEGER).build();
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(SystemColumns.ROWKEY_NAME, SqlTypes.STRING).valueColumn(COL0, SqlTypes.array(inner)).build();
    expressionTypeManager = new ExpressionTypeManager(schema, functionRegistry);
    final Expression expression = new DereferenceExpression(Optional.empty(), new SubscriptExpression(TestExpressions.COL0, new IntegerLiteral(1)), "IN0");
    // When:
    final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    assertThat(result, is(SqlTypes.INTEGER));
}
Also used : SqlStruct(io.confluent.ksql.schema.ksql.types.SqlStruct) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) 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) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) 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