throw new UnsupportedOperationException("unknown rex " + node);
}
}
RexNode toRex(RelInput relInput, Object o) {
final RelOptCluster cluster = relInput.getCluster();
final RexBuilder rexBuilder = cluster.getRexBuilder();
if (o == null) {
return null;
} else if (o instanceof Map) {
Map map = (Map) o;
final String op = (String) map.get("op");
if (op != null) {
final List operands = (List) map.get("operands");
final Object jsonType = map.get("type");
if (jsonType != null) {
RelDataType type = toType(cluster.getTypeFactory(), jsonType);
return rexBuilder.makeCall(
type, toOp(op, map), toRexList(relInput, operands));
} else {
return rexBuilder.makeCall(
toOp(op, map), toRexList(relInput, operands));
}
}
final Integer input = (Integer) map.get("input");
if (input != null) {
List<RelNode> inputNodes = relInput.getInputs();
int i = input;
for (RelNode inputNode : inputNodes) {
final RelDataType rowType = inputNode.getRowType();
if (i < rowType.getFieldCount()) {
final RelDataTypeField field = rowType.getFieldList().get(i);
return rexBuilder.makeInputRef(field.getType(), input);
}
i -= rowType.getFieldCount();
}
throw new RuntimeException("input field " + input + " is out of range");
}
final String field = (String) map.get("field");
if (field != null) {
final Object jsonExpr = map.get("expr");
final RexNode expr = toRex(relInput, jsonExpr);
return rexBuilder.makeFieldAccess(expr, field, true);
}
final String correl = (String) map.get("correl");
if (correl != null) {
final Object jsonType = map.get("type");
RelDataType type = toType(cluster.getTypeFactory(), jsonType);
return rexBuilder.makeCorrel(type, correl);
}
if (map.containsKey("literal")) {
final Object literal = map.get("literal");
final SqlTypeName sqlTypeName =