Search in sources :

Example 1 with LambdaFunction1Term

use of io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term in project ksql by confluentinc.

the class TermCompiler method visitLambdaExpression.

@Override
public Term visitLambdaExpression(final LambdaFunctionCall lambdaFunctionCall, final Context context) {
    final Term lambdaBody = process(lambdaFunctionCall.getBody(), context);
    final ImmutableList.Builder<Pair<String, SqlType>> nameToType = ImmutableList.builder();
    for (final String lambdaArg : lambdaFunctionCall.getArguments()) {
        nameToType.add(Pair.of(lambdaArg, context.getLambdaSqlTypeMapping().get((lambdaArg))));
    }
    switch(lambdaFunctionCall.getArguments().size()) {
        case 1:
            return new LambdaFunction1Term(nameToType.build(), lambdaBody);
        case 2:
            return new LambdaFunction2Term(nameToType.build(), lambdaBody);
        case 3:
            return new LambdaFunction3Term(nameToType.build(), lambdaBody);
        default:
            throw new KsqlException("Interpreter only supports lambdas up to three arguments");
    }
}
Also used : LambdaFunction3Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction3Term) ImmutableList(com.google.common.collect.ImmutableList) Term(io.confluent.ksql.execution.interpreter.terms.Term) LambdaFunction3Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction3Term) ColumnReferenceTerm(io.confluent.ksql.execution.interpreter.terms.ColumnReferenceTerm) LambdaFunction1Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term) LikeTerm(io.confluent.ksql.execution.interpreter.terms.LikeTerm) FunctionCallTerm(io.confluent.ksql.execution.interpreter.terms.FunctionCallTerm) SearchedCaseTerm(io.confluent.ksql.execution.interpreter.terms.SearchedCaseTerm) StructTerm(io.confluent.ksql.execution.interpreter.terms.StructTerm) LambdaVariableTerm(io.confluent.ksql.execution.interpreter.terms.LambdaVariableTerm) CreateMapTerm(io.confluent.ksql.execution.interpreter.terms.CreateMapTerm) LambdaFunction2Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction2Term) SubscriptTerm(io.confluent.ksql.execution.interpreter.terms.SubscriptTerm) NotTerm(io.confluent.ksql.execution.interpreter.terms.NotTerm) IsNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNullTerm) CreateArrayTerm(io.confluent.ksql.execution.interpreter.terms.CreateArrayTerm) DereferenceTerm(io.confluent.ksql.execution.interpreter.terms.DereferenceTerm) IsNotNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNotNullTerm) InPredicateTerm(io.confluent.ksql.execution.interpreter.terms.InPredicateTerm) LambdaFunction1Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term) LambdaFunction2Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction2Term) KsqlException(io.confluent.ksql.util.KsqlException) Pair(io.confluent.ksql.util.Pair)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ColumnReferenceTerm (io.confluent.ksql.execution.interpreter.terms.ColumnReferenceTerm)1 CreateArrayTerm (io.confluent.ksql.execution.interpreter.terms.CreateArrayTerm)1 CreateMapTerm (io.confluent.ksql.execution.interpreter.terms.CreateMapTerm)1 DereferenceTerm (io.confluent.ksql.execution.interpreter.terms.DereferenceTerm)1 FunctionCallTerm (io.confluent.ksql.execution.interpreter.terms.FunctionCallTerm)1 InPredicateTerm (io.confluent.ksql.execution.interpreter.terms.InPredicateTerm)1 IsNotNullTerm (io.confluent.ksql.execution.interpreter.terms.IsNotNullTerm)1 IsNullTerm (io.confluent.ksql.execution.interpreter.terms.IsNullTerm)1 LambdaFunction1Term (io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term)1 LambdaFunction2Term (io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction2Term)1 LambdaFunction3Term (io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction3Term)1 LambdaVariableTerm (io.confluent.ksql.execution.interpreter.terms.LambdaVariableTerm)1 LikeTerm (io.confluent.ksql.execution.interpreter.terms.LikeTerm)1 NotTerm (io.confluent.ksql.execution.interpreter.terms.NotTerm)1 SearchedCaseTerm (io.confluent.ksql.execution.interpreter.terms.SearchedCaseTerm)1 StructTerm (io.confluent.ksql.execution.interpreter.terms.StructTerm)1 SubscriptTerm (io.confluent.ksql.execution.interpreter.terms.SubscriptTerm)1 Term (io.confluent.ksql.execution.interpreter.terms.Term)1 KsqlException (io.confluent.ksql.util.KsqlException)1