Search in sources :

Example 1 with SubscriptTerm

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

the class TermCompiler method visitSubscriptExpression.

@Override
public Term visitSubscriptExpression(final SubscriptExpression node, final Context context) {
    final SqlType internalSchema = expressionTypeManager.getExpressionSqlType(node.getBase(), context.getLambdaSqlTypeMapping());
    switch(internalSchema.baseType()) {
        case ARRAY:
            final SqlArray array = (SqlArray) internalSchema;
            final Term listTerm = process(node.getBase(), context);
            final Term indexTerm = process(node.getIndex(), context);
            return new SubscriptTerm(listTerm, indexTerm, (o, index) -> ArrayAccess.arrayAccess(((List<?>) o), (Integer) index), array.getItemType());
        case MAP:
            final SqlMap mapSchema = (SqlMap) internalSchema;
            final Term mapTerm = process(node.getBase(), context);
            final Term keyTerm = process(node.getIndex(), context);
            return new SubscriptTerm(mapTerm, keyTerm, (map, key) -> ((Map<?, ?>) map).get(key), mapSchema.getValueType());
        default:
            throw new UnsupportedOperationException();
    }
}
Also used : SqlMap(io.confluent.ksql.schema.ksql.types.SqlMap) 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) SqlArray(io.confluent.ksql.schema.ksql.types.SqlArray) SubscriptTerm(io.confluent.ksql.execution.interpreter.terms.SubscriptTerm)

Aggregations

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 SqlArray (io.confluent.ksql.schema.ksql.types.SqlArray)1 SqlMap (io.confluent.ksql.schema.ksql.types.SqlMap)1