Search in sources :

Example 21 with LambdaFunctionCall

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

the class ExpressionFormatterTest method shouldFormatLambdaExpression.

@Test
public void shouldFormatLambdaExpression() {
    // Given:
    final LambdaFunctionCall expression = new LambdaFunctionCall(Optional.of(LOCATION), ImmutableList.of("X", "Y"), new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, new LambdaVariable("X"), new LambdaVariable("Y")));
    // When:
    final String text = ExpressionFormatter.formatExpression(expression);
    // Then:
    assertThat(text, equalTo("(X, Y) => (X OR Y)"));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) Test(org.junit.Test)

Example 22 with LambdaFunctionCall

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

the class AstBuilderTest method shouldBuildNestedLambdaFunction.

@Test
public void shouldBuildNestedLambdaFunction() {
    // Given:
    final SingleStatementContext stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, (X,Y) => TRANSFORM_ARRAY(Col4, X => 5)) FROM TEST1;");
    // When:
    final Query result = (Query) builder.buildStatement(stmt);
    // Then:
    assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column("COL4"), new LambdaFunctionCall(ImmutableList.of("X", "Y"), new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column("COL4"), new LambdaFunctionCall(ImmutableList.of("X"), new IntegerLiteral(5))))))), Optional.empty())))));
}
Also used : Query(io.confluent.ksql.parser.tree.Query) SingleStatementContext(io.confluent.ksql.parser.SqlBaseParser.SingleStatementContext) 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

LambdaFunctionCall (io.confluent.ksql.execution.expression.tree.LambdaFunctionCall)22 Test (org.junit.Test)20 FunctionCall (io.confluent.ksql.execution.expression.tree.FunctionCall)18 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)17 LambdaVariable (io.confluent.ksql.execution.expression.tree.LambdaVariable)17 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)15 Expression (io.confluent.ksql.execution.expression.tree.Expression)14 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)13 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)12 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)12 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)12 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)12 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)12 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)12 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)11 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)8 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)7 KsqlScalarFunction (io.confluent.ksql.function.KsqlScalarFunction)7 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)7 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)5