Search in sources :

Example 51 with FunctionCall

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

the class GenericExpressionResolverTest method shouldResolveArbitraryExpressions.

@Test
public void shouldResolveArbitraryExpressions() {
    // Given:
    final SqlType type = SqlTypes.struct().field("FOO", SqlTypes.STRING).build();
    final Expression exp = new CreateStructExpression(ImmutableList.of(new Field("FOO", new FunctionCall(FunctionName.of("CONCAT"), ImmutableList.of(new StringLiteral("bar"), new StringLiteral("baz"))))));
    // When:
    final Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
    // Then:
    assertThat(o, is(new Struct(SchemaBuilder.struct().field("FOO", Schema.OPTIONAL_STRING_SCHEMA).optional().build()).put("FOO", "barbaz")));
}
Also used : Field(io.confluent.ksql.execution.expression.tree.CreateStructExpression.Field) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Example 52 with FunctionCall

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

the class AstSanitizerTest method shouldAllowNestedLambdaFunctionsWithoutDuplicate.

@Test
public void shouldAllowNestedLambdaFunctionsWithoutDuplicate() {
    // Given:
    final Statement stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, (X,Y,Z) => TRANSFORM_MAP(Col4, Q => 4, H => 5), (X,Y,Z) => 0) FROM TEST1;");
    // When:
    final Query result = (Query) AstSanitizer.sanitize(stmt, META_STORE, true);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column(TEST1_NAME, "COL4"), new LambdaFunctionCall(ImmutableList.of("X", "Y", "Z"), new FunctionCall(FunctionName.of("TRANSFORM_MAP"), ImmutableList.of(column(TEST1_NAME, "COL4"), new LambdaFunctionCall(ImmutableList.of("Q"), new IntegerLiteral(4)), new LambdaFunctionCall(ImmutableList.of("H"), new IntegerLiteral(5))))), new LambdaFunctionCall(ImmutableList.of("X", "Y", "Z"), new IntegerLiteral(0)))), Optional.of(ColumnName.of("KSQL_COL_0")))))));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) ParsedStatement(io.confluent.ksql.parser.KsqlParser.ParsedStatement) Statement(io.confluent.ksql.parser.tree.Statement) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) Select(io.confluent.ksql.parser.tree.Select) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) 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

FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)52 Test (org.junit.Test)47 LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)34 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)22 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)22 Expression (io.confluent.ksql.execution.expression.tree.Expression)21 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)17 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)17 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)16 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)16 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)16 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)16 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)16 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)16 LambdaVariable (io.confluent.ksql.execution.expression.tree.LambdaVariable)15 KsqlScalarFunction (io.confluent.ksql.function.KsqlScalarFunction)13 UdfFactory (io.confluent.ksql.function.UdfFactory)13 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)11 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)11 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)11