private static VectorExpressionWriter genVectorExpressionWritableUnion(
      SettableUnionObjectInspector fieldObjInspector) throws HiveException {

    return new VectorExpressionWriterMap() {
      private Object obj;
      private VectorExtractRow vectorExtractRow;
      private UnionTypeInfo unionTypeInfo;

      public VectorExpressionWriter init(SettableUnionObjectInspector objInspector) throws HiveException {
        super.init(objInspector);
        obj = initValue(null);
        vectorExtractRow = new VectorExtractRow();
        unionTypeInfo = (UnionTypeInfo)
            TypeInfoUtils.getTypeInfoFromTypeString(objInspector.getTypeName());
        return this;
      }

      @Override
      public Object initValue(Object ignored) {
        return ((SettableUnionObjectInspector) this.objectInspector).create();
      }

      @Override
      public Object writeValue(ColumnVector column, int row)
          throws HiveException {

        final UnionColumnVector unionColumnVector = (UnionColumnVector) column;
        final int tag = unionColumnVector.tags[row];
        final SettableUnionObjectInspector unionOI =
            (SettableUnionObjectInspector) this.objectInspector;
        ObjectInspector fieldOI = unionOI.getObjectInspectors().get(tag);
        ColumnVector fieldColVector = unionColumnVector.fields[tag];
        final Object value =
            vectorExtractRow.extractRowColumn(
                fieldColVector, unionTypeInfo.getAllUnionObjectTypeInfos().get(tag), fieldOI, row);
        if (value == null) {
          return null;
        }

        unionOI.setFieldAndTag(obj, value, (byte) tag);
        return obj;
      }

      @Override
      public Object setValue(Object union, ColumnVector column, int row)
          throws HiveException {
        if (union == null) {
          union = initValue(null);
        }

        final UnionColumnVector unionColumnVector = (UnionColumnVector) column;
        final int tag = unionColumnVector.tags[row];
        final SettableUnionObjectInspector unionOI =
            (SettableUnionObjectInspector) this.objectInspector;
        ObjectInspector fieldOI = unionOI.getObjectInspectors().get(tag);
        ColumnVector fieldColVector = unionColumnVector.fields[tag];
        final Object value =
            vectorExtractRow.extractRowColumn(
                fieldColVector, unionTypeInfo.getAllUnionObjectTypeInfos().get(tag), fieldOI, row);
        if (value == null) {
          return null;
        }

        unionOI.setFieldAndTag(union, value, (byte) tag);
        return union;
      }
    }.init(fieldObjInspector);
  }
Compiles the appropriate vector expression writers based on a struct object
inspector.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/expressions/VectorExpressionWriterFactory.java