private ConstantObjectInspector createConstantObjectInspector(RexNode expr) {
    if (RexUtil.isLiteral(expr, true)) { // Literal or cast on literal
      final ExprNodeConstantDesc constant;
      if (expr.isA(SqlKind.LITERAL)) {
        constant = ExprNodeConverter.toExprNodeConstantDesc((RexLiteral) expr);
      } else {
        RexNode foldedExpr = foldExpression(expr);
        if (!foldedExpr.isA(SqlKind.LITERAL)) {
          // Constant could not be generated
          return null;
        }
        constant = ExprNodeConverter.toExprNodeConstantDesc((RexLiteral) foldedExpr);
      }
      PrimitiveTypeInfo typeInfo = (PrimitiveTypeInfo) constant.getTypeInfo();
      Object value = constant.getValue();
      Object writableValue = value == null ? null :
          PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(typeInfo)
              .getPrimitiveWritableObject(value);
      return PrimitiveObjectInspectorFactory.getPrimitiveWritableConstantObjectInspector(
          typeInfo, writableValue);
    } else if (expr instanceof RexCall) {
      RexCall call = (RexCall) expr;
      if (call.getOperator() == SqlStdOperatorTable.ROW) { // Struct
        List<String> fieldNames = new ArrayList<>();
        List<ObjectInspector> fieldObjectInspectors = new ArrayList<>();
        List<Object> writableValues = new ArrayList<>();
        for (int i = 0; i < call.getOperands().size(); i++) {
          RexNode input = call.getOperands().get(i);
          ConstantObjectInspector objectInspector = createConstantObjectInspector(input);
          if (objectInspector == null) {
            // Constant could not be generated
            return null;
          }
          fieldNames.add(expr.getType().getFieldList().get(i).getName());
          fieldObjectInspectors.add(objectInspector);
          writableValues.add(objectInspector.getWritableConstantValue());
        }
        return ObjectInspectorFactory.getStandardConstantStructObjectInspector(
            fieldNames,
            fieldObjectInspectors,
            writableValues);
      } else if (call.getOperator() == SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR) { // List
        ListTypeInfo listTypeInfo = (ListTypeInfo) TypeConverter.convert(expr.getType());
        TypeInfo typeInfo = listTypeInfo.getListElementTypeInfo();
        List<Object> writableValues = new ArrayList<>();
        for (RexNode input : call.getOperands()) {
          ConstantObjectInspector objectInspector = createConstantObjectInspector(input);
          if (objectInspector == null) {
            // Constant could not be generated
            return null;
          }
          writableValues.add(objectInspector.getWritableConstantValue());
        }
        return ObjectInspectorFactory.getStandardConstantListObjectInspector(
            ObjectInspectorUtils.getStandardObjectInspector(
                TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(typeInfo),
                ObjectInspectorCopyOption.WRITABLE),
            writableValues);
      } else if (call.getOperator() == SqlStdOperatorTable.MAP_VALUE_CONSTRUCTOR) { // Map
        MapTypeInfo mapTypeInfo = (MapTypeInfo) TypeConverter.convert(expr.getType());
        Map<Object, Object> writableValues = new HashMap<>();
        Iterator<RexNode> it = call.getOperands().iterator();
        while (it.hasNext()) {
          ConstantObjectInspector keyObjectInspector = createConstantObjectInspector(it.next());
          if (keyObjectInspector == null) {
            // Constant could not be generated
            return null;
          }
          ConstantObjectInspector valueObjectInspector = createConstantObjectInspector(it.next());
          if (valueObjectInspector == null) {
            // Constant could not be generated
            return null;
          }
          writableValues.put(
              keyObjectInspector.getWritableConstantValue(),
              valueObjectInspector.getWritableConstantValue());
        }
        return ObjectInspectorFactory.getStandardConstantMapObjectInspector(
            ObjectInspectorUtils.getStandardObjectInspector(
                TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(mapTypeInfo.getMapKeyTypeInfo()),
                ObjectInspectorCopyOption.WRITABLE),
            ObjectInspectorUtils.getStandardObjectInspector(
                TypeInfoUtils.getStandardJavaObjectInspectorFromTypeInfo(mapTypeInfo.getMapValueTypeInfo()),
                ObjectInspectorCopyOption.WRITABLE),
            writableValues);
      }
    }
    // Constant could not be generated
    return null;
  }
Returns constant object inspector or null if it could not be generated.
ql/src/java/org/apache/hadoop/hive/ql/parse/type/HiveFunctionHelper.java