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();
}
}
Aggregations