@Override
  public ObjectInspector initialize(ObjectInspector rowInspector) throws HiveException {
    deferredChildren = new GenericUDF.DeferredObject[children.length];
    List<GenericUDF.DeferredObject> childrenNeedingPrepare =
        new ArrayList<GenericUDF.DeferredObject>(children.length);
    for (int i = 0; i < deferredChildren.length; i++) {
      DeferredExprObject deferredExprObject = new DeferredExprObject(children[i], isEager);
      deferredChildren[i] = deferredExprObject;
      if (deferredExprObject.needsPrepare()) {
        childrenNeedingPrepare.add(deferredExprObject);
      }
    }
    this.childrenNeedingPrepare =
        childrenNeedingPrepare.toArray(new GenericUDF.DeferredObject[childrenNeedingPrepare.size()]);
    // Initialize all children first
    ObjectInspector[] childrenOIs = new ObjectInspector[children.length];
    for (int i = 0; i < children.length; i++) {
      childrenOIs[i] = children[i].initialize(rowInspector);
    }
    MapredContext context = MapredContext.get();
    // It is possible that there is no context at this point. For example a context is not created
    // when "hive.fetch.task.conversion" occurs.
    if (context != null) {
      context.setup(genericUDF);
    } else if (MapredContext.needConfigure(genericUDF)) {
      // It is a bit unfortunate that currently the UDF configuration signature expects a
      // MapredContext (even if execution is tez or another engine) - this causes an
      // impedence mismatch. For example: MapredContext has Reporter objects that may or
      // may not make sense for the current engine.
      //
      // We attempt to create a dummyContext that has at least access to a Configuration
      // object.
      MapredContext dummyContext = MapredContext.createDummy(getBestAvailableConf());
      dummyContext.setup(genericUDF);
    }
    outputOI = genericUDF.initializeAndFoldConstants(childrenOIs);
    isConstant = ObjectInspectorUtils.isConstantObjectInspector(outputOI)
        && isConsistentWithinQuery();
    return outputOI;
  }
Class to allow deferred evaluation for GenericUDF.
ql/src/java/org/apache/hadoop/hive/ql/exec/ExprNodeGenericFuncEvaluator.java