public static Object getWritablePrimitiveObject(PrimitiveTypeInfo primitiveTypeInfo,
      ObjectInspector objectInspector, DataTypePhysicalVariation dataTypePhysicalVariation,
      Object object) {

    switch (primitiveTypeInfo.getPrimitiveCategory()) {
    case BOOLEAN:
      {
        WritableBooleanObjectInspector writableOI = (WritableBooleanObjectInspector) objectInspector;
        if (object instanceof Boolean) {
          return writableOI.create((boolean) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case BYTE:
      {
        WritableByteObjectInspector writableOI = (WritableByteObjectInspector) objectInspector;
        if (object instanceof Byte) {
          return writableOI.create((byte) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case SHORT:
      {
        WritableShortObjectInspector writableOI = (WritableShortObjectInspector) objectInspector;
        if (object instanceof Short) {
          return writableOI.create((short) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case INT:
      {
        WritableIntObjectInspector writableOI = (WritableIntObjectInspector) objectInspector;
        if (object instanceof Integer) {
          return writableOI.create((int) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case LONG:
      {
        WritableLongObjectInspector writableOI = (WritableLongObjectInspector) objectInspector;
        if (object instanceof Long) {
          return writableOI.create((long) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case DATE:
      {
        WritableDateObjectInspector writableOI = (WritableDateObjectInspector) objectInspector;
        if (object instanceof Date) {
          return writableOI.create((Date) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case FLOAT:
      {
        WritableFloatObjectInspector writableOI = (WritableFloatObjectInspector) objectInspector;
        if (object instanceof Float) {
          return writableOI.create((float) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case DOUBLE:
      {
        WritableDoubleObjectInspector writableOI = (WritableDoubleObjectInspector) objectInspector;
        if (object instanceof Double) {
          return writableOI.create((double) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case STRING:
      {
        WritableStringObjectInspector writableOI = (WritableStringObjectInspector) objectInspector;
        if (object instanceof String) {
          return writableOI.create((String) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case CHAR:
      {
        WritableHiveCharObjectInspector writableCharObjectInspector =
            new WritableHiveCharObjectInspector( (CharTypeInfo) primitiveTypeInfo);
        if (object instanceof HiveChar) {
          return writableCharObjectInspector.create((HiveChar) object);
        } else {
          return writableCharObjectInspector.copyObject(object);
        }
      }
    case VARCHAR:
      {
        WritableHiveVarcharObjectInspector writableVarcharObjectInspector =
            new WritableHiveVarcharObjectInspector( (VarcharTypeInfo) primitiveTypeInfo);
        if (object instanceof HiveVarchar) {
          return writableVarcharObjectInspector.create((HiveVarchar) object);
        } else {
          return writableVarcharObjectInspector.copyObject(object);
        }
      }
    case BINARY:
      {
        if (object instanceof byte[]) {
          return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector.create((byte[]) object);
        } else {
          return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector.copyObject(object);
        }
      }
    case TIMESTAMP:
    {
      WritableTimestampObjectInspector writableOI = (WritableTimestampObjectInspector) objectInspector;
      if (object instanceof Timestamp) {
        return writableOI.create((Timestamp) object);
      } else {
        return writableOI.copyObject(object);
      }
    }
    case INTERVAL_YEAR_MONTH:
      {
        WritableHiveIntervalYearMonthObjectInspector writableOI = (WritableHiveIntervalYearMonthObjectInspector) objectInspector;
        if (object instanceof HiveIntervalYearMonth) {
          return writableOI.create((HiveIntervalYearMonth) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case INTERVAL_DAY_TIME:
      {
        WritableHiveIntervalDayTimeObjectInspector writableOI = (WritableHiveIntervalDayTimeObjectInspector) objectInspector;
        if (object instanceof HiveIntervalDayTime) {
          return writableOI.create((HiveIntervalDayTime) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    case DECIMAL:
      {
        // Do not represent DECIMAL_64 to make ROW mode tests easier --
        // make the VECTOR mode tests convert into the VectorizedRowBatch.
        WritableHiveDecimalObjectInspector writableOI =
            new WritableHiveDecimalObjectInspector((DecimalTypeInfo) primitiveTypeInfo);
        if (object instanceof HiveDecimal) {
          return writableOI.create((HiveDecimal) object);
        } else {
          return writableOI.copyObject(object);
        }
      }
    default:
      throw new Error("Unknown primitive category " + primitiveTypeInfo.getPrimitiveCategory());
    }
  }
Generate object inspector and random row object[].
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/VectorRandomRowSource.java