Search in sources :

Example 1 with CreateMapTerm

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

the class TermCompiler method visitCreateMapExpression.

@Override
public Term visitCreateMapExpression(final CreateMapExpression exp, final Context context) {
    final ImmutableMap<Expression, Expression> map = exp.getMap();
    final List<Expression> keys = CoercionUtil.coerceUserList(map.keySet(), expressionTypeManager, context.getLambdaSqlTypeMapping()).expressions();
    final List<Expression> values = CoercionUtil.coerceUserList(map.values(), expressionTypeManager, context.getLambdaSqlTypeMapping()).expressions();
    final Iterable<Pair<Expression, Expression>> pairs = () -> Streams.zip(keys.stream(), values.stream(), Pair::of).iterator();
    final ImmutableMap.Builder<Term, Term> mapTerms = ImmutableMap.builder();
    for (Pair<Expression, Expression> p : pairs) {
        mapTerms.put(process(p.getLeft(), context), process(p.getRight(), context));
    }
    final SqlType resultType = expressionTypeManager.getExpressionSqlType(exp, context.getLambdaSqlTypeMapping());
    return new CreateMapTerm(mapTerms.build(), resultType);
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) CreateMapTerm(io.confluent.ksql.execution.interpreter.terms.CreateMapTerm) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) 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) ImmutableMap(com.google.common.collect.ImmutableMap) Pair(io.confluent.ksql.util.Pair)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)1 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)1 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)1 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)1 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)1 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)1 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)1 Expression (io.confluent.ksql.execution.expression.tree.Expression)1 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)1 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)1 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)1 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)1 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)1 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)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