Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#writableDoubleObjectInspector()

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#writableDoubleObjectInspector() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArrayWritableObjectInspector.java    From indexr with Apache License 2.0 6 votes vote down vote up
private ObjectInspector getObjectInspector(final TypeInfo typeInfo) {
    if (typeInfo.equals(TypeInfoFactory.doubleTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.booleanTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.floatTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.intTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.longTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.stringTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.timestampTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableTimestampObjectInspector;
    } else if (typeInfo.equals(TypeInfoFactory.dateTypeInfo)) {
        return PrimitiveObjectInspectorFactory.writableDateObjectInspector;
    } else {
        throw new UnsupportedOperationException("Unknown field type: " + typeInfo);
    }
}
 
Example 2
Source File: FFMPredictGenericUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector init(Mode mode, ObjectInspector[] parameters) throws HiveException {
    assert (parameters.length == 5);
    super.init(mode, parameters);

    // initialize input
    if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from original data
        this.wiOI = HiveUtils.asDoubleCompatibleOI(parameters, 0);
        this.vijOI = HiveUtils.asListOI(parameters, 1);
        this.vijElemOI = HiveUtils.asFloatingPointOI(vijOI.getListElementObjectInspector());
        this.vjiOI = HiveUtils.asListOI(parameters, 2);
        this.vjiElemOI = HiveUtils.asFloatingPointOI(vjiOI.getListElementObjectInspector());
        this.xiOI = HiveUtils.asDoubleCompatibleOI(parameters, 3);
        this.xjOI = HiveUtils.asDoubleCompatibleOI(parameters, 4);
    } else {// from partial aggregation
        this.mergeInputOI = HiveUtils.asDoubleOI(parameters, 0);
    }

    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
}
 
Example 3
Source File: ArrayAvgGenericUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
void merge(final int o_size, @Nonnull final Object o_sum, @Nonnull final Object o_count,
        @Nonnull final StandardListObjectInspector sumOI,
        @Nonnull final StandardListObjectInspector countOI) throws HiveException {
    final WritableDoubleObjectInspector sumElemOI =
            PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    final WritableLongObjectInspector countElemOI =
            PrimitiveObjectInspectorFactory.writableLongObjectInspector;

    if (o_size != _size) {
        if (_size == -1) {
            init(o_size);
        } else {
            throw new HiveException("Mismatch in the number of elements");
        }
    }
    final double[] sum = _sum;
    final long[] count = _count;
    for (int i = 0, len = _size; i < len; i++) {
        Object sum_e = sumOI.getListElement(o_sum, i);
        sum[i] += sumElemOI.get(sum_e);
        Object count_e = countOI.getListElement(o_count, i);
        count[i] += countElemOI.get(count_e);
    }
}
 
Example 4
Source File: OkapiBM25UDF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(@Nonnull ObjectInspector[] argOIs)
        throws UDFArgumentException {
    final int numArgOIs = argOIs.length;
    if (numArgOIs < 5) {
        showHelp("#arguments must be greater than or equal to 5: " + numArgOIs);
    } else if (numArgOIs == 6) {
        String opts = HiveUtils.getConstString(argOIs[5]);
        processOptions(opts);
    }

    this.frequencyOI = HiveUtils.asDoubleCompatibleOI(argOIs[0]);
    this.docLengthOI = HiveUtils.asIntegerOI(argOIs[1]);
    this.averageDocLengthOI = HiveUtils.asDoubleCompatibleOI(argOIs[2]);
    this.numDocsOI = HiveUtils.asIntegerOI(argOIs[3]);
    this.numDocsWithTermOI = HiveUtils.asIntegerOI(argOIs[4]);

    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
}
 
Example 5
Source File: KPAPredictUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException {
    super.init(m, parameters);

    // initialize input
    if (m == Mode.PARTIAL1 || m == Mode.COMPLETE) {// from original data
        this.xhOI = HiveUtils.asNumberOI(parameters[0]);
        this.xkOI = HiveUtils.asNumberOI(parameters[1]);
        this.w0OI = HiveUtils.asNumberOI(parameters[2]);
        this.w1OI = HiveUtils.asNumberOI(parameters[3]);
        this.w2OI = HiveUtils.asNumberOI(parameters[4]);
        this.w3OI = HiveUtils.asNumberOI(parameters[5]);
    }

    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
}
 
Example 6
Source File: TreePredictUDFv1.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 4 && argOIs.length != 5) {
        throw new UDFArgumentException("tree_predict_v1 takes 4 or 5 arguments");
    }

    this.modelTypeOI = HiveUtils.asIntegerOI(argOIs, 1);
    this.stringOI = HiveUtils.asStringOI(argOIs, 2);
    ListObjectInspector listOI = HiveUtils.asListOI(argOIs, 3);
    this.featureListOI = listOI;
    ObjectInspector elemOI = listOI.getListElementObjectInspector();
    this.featureElemOI = HiveUtils.asDoubleCompatibleOI(elemOI);

    boolean classification = false;
    if (argOIs.length == 5) {
        classification = HiveUtils.getConstBoolean(argOIs, 4);
    }
    this.classification = classification;

    if (classification) {
        return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    } else {
        return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    }
}
 
Example 7
Source File: RandomForestEnsembleUDAF.java    From incubator-hivemall with Apache License 2.0 6 votes vote down vote up
void merge(int size, @Nonnull Object posterioriObj,
        @Nonnull StandardListObjectInspector posterioriOI) throws HiveException {

    if (size != _k) {
        if (_k == -1) {
            this._k = size;
            this._posteriori = new double[size];
        } else {
            throw new HiveException(
                "Mismatch in the number of elements: _k=" + _k + ", size=" + size);
        }
    }

    final double[] posteriori = _posteriori;
    final DoubleObjectInspector doubleOI =
            PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    for (int i = 0, len = _k; i < len; i++) {
        Object o2 = posterioriOI.getListElement(posterioriObj, i);
        posteriori[i] += doubleOI.get(o2);
    }
}
 
Example 8
Source File: MFPredictionUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length < 2 || argOIs.length > 5) {
        throw new UDFArgumentException("mf_predict takes 2~5 arguments: " + argOIs.length);
    }

    this.puOI = HiveUtils.asListOI(argOIs, 0);
    this.puElemOI = HiveUtils.asFloatingPointOI(puOI.getListElementObjectInspector());
    this.qiOI = HiveUtils.asListOI(argOIs, 1);
    this.qiElemOI = HiveUtils.asFloatingPointOI(qiOI.getListElementObjectInspector());

    switch (argOIs.length) {
        case 3:
            this.muOI = HiveUtils.asNumberOI(argOIs, 2);
            break;
        case 4:
            this.buOI = HiveUtils.asNumberOI(argOIs, 2);
            this.biOI = HiveUtils.asNumberOI(argOIs, 3);
            break;
        case 5:
            this.buOI = HiveUtils.asNumberOI(argOIs, 2);
            this.biOI = HiveUtils.asNumberOI(argOIs, 3);
            this.muOI = HiveUtils.asNumberOI(argOIs, 4);
            break;
        default:
            break;
    }

    this.result = new DoubleWritable();
    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
}
 
Example 9
Source File: OrcLazyObjectInspectorUtils.java    From hive-dwrf with Apache License 2.0 5 votes vote down vote up
public static ObjectInspector createWritableObjectInspector(int columnId,
                                             List<OrcProto.Type> types){
  OrcProto.Type type = types.get(columnId);
  switch (type.getKind()) {
    case FLOAT:
      return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
    case DOUBLE:
      return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    case BOOLEAN:
      return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
    case BYTE:
      return PrimitiveObjectInspectorFactory.writableByteObjectInspector;
    case SHORT:
      return PrimitiveObjectInspectorFactory.writableShortObjectInspector;
    case INT:
      return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
    case LONG:
      return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    case BINARY:
      return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
    case STRING:
      return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    case TIMESTAMP:
      return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
    case STRUCT:
      return new OrcStruct.OrcStructInspector(columnId, types);
    case UNION:
      return new OrcUnion.OrcUnionObjectInspector(columnId, types);
    case MAP:
      return new OrcStruct.OrcMapObjectInspector(columnId, types);
    case LIST:
      return new OrcStruct.OrcListObjectInspector(columnId, types);
    default:
      throw new UnsupportedOperationException("Unknown type " +
        type.getKind());
  }
}
 
Example 10
Source File: ArrayWritableObjectInspector.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private ObjectInspector getObjectInspector(final TypeInfo typeInfo) {
  if (typeInfo.equals(TypeInfoFactory.doubleTypeInfo)) {
    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
  } else if (typeInfo.equals(TypeInfoFactory.booleanTypeInfo)) {
    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
  } else if (typeInfo.equals(TypeInfoFactory.floatTypeInfo)) {
    return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
  } else if (typeInfo.equals(TypeInfoFactory.intTypeInfo)) {
    return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
  } else if (typeInfo.equals(TypeInfoFactory.longTypeInfo)) {
    return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
  } else if (typeInfo.equals(TypeInfoFactory.stringTypeInfo)) {
    return ParquetPrimitiveInspectorFactory.parquetStringInspector;
  } else if (typeInfo.getCategory().equals(Category.STRUCT)) {
    return new ArrayWritableObjectInspector((StructTypeInfo) typeInfo);
  } else if (typeInfo.getCategory().equals(Category.LIST)) {
    final TypeInfo subTypeInfo = ((ListTypeInfo) typeInfo).getListElementTypeInfo();
    return new ParquetHiveArrayInspector(getObjectInspector(subTypeInfo));
  } else if (typeInfo.getCategory().equals(Category.MAP)) {
    final TypeInfo keyTypeInfo = ((MapTypeInfo) typeInfo).getMapKeyTypeInfo();
    final TypeInfo valueTypeInfo = ((MapTypeInfo) typeInfo).getMapValueTypeInfo();
    if (keyTypeInfo.equals(TypeInfoFactory.stringTypeInfo) || keyTypeInfo.equals(TypeInfoFactory.byteTypeInfo)
            || keyTypeInfo.equals(TypeInfoFactory.shortTypeInfo)) {
      return new DeepParquetHiveMapInspector(getObjectInspector(keyTypeInfo), getObjectInspector(valueTypeInfo));
    } else {
      return new StandardParquetHiveMapInspector(getObjectInspector(keyTypeInfo), getObjectInspector(valueTypeInfo));
    }
  } else if (typeInfo.equals(TypeInfoFactory.timestampTypeInfo)) {
    throw new UnsupportedOperationException("timestamp not implemented yet");
  } else if (typeInfo.equals(TypeInfoFactory.byteTypeInfo)) {
    return ParquetPrimitiveInspectorFactory.parquetByteInspector;
  } else if (typeInfo.equals(TypeInfoFactory.shortTypeInfo)) {
    return ParquetPrimitiveInspectorFactory.parquetShortInspector;
  } else {
    throw new IllegalArgumentException("Unknown field info: " + typeInfo);
  }

}
 
Example 11
Source File: FeatureUDFTest.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Test
public void testTextDoubleWritable() throws Exception {
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableStringObjectInspector;
    ObjectInspector weightOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    udf.initialize(new ObjectInspector[] {featureOI, weightOI});

    Text ret = udf.evaluate(
        new GenericUDF.DeferredObject[] {new DeferredJavaObject(new Text("f1")),
                new DeferredJavaObject(new DoubleWritable(2.5d))});

    Assert.assertEquals("f1:2.5", ret.toString());
}
 
Example 12
Source File: HaversineDistanceUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 4 && argOIs.length != 5) {
        throw new UDFArgumentException("_FUNC_ takes 4 or 5 arguments: " + argOIs.length);
    }
    this.lat1OI = HiveUtils.asDoubleCompatibleOI(argOIs[0]);
    this.lon1OI = HiveUtils.asDoubleCompatibleOI(argOIs[1]);
    this.lat2OI = HiveUtils.asDoubleCompatibleOI(argOIs[2]);
    this.lon2OI = HiveUtils.asDoubleCompatibleOI(argOIs[3]);
    this.inMiles = (argOIs.length == 5) && HiveUtils.getConstBoolean(argOIs[4]);

    this.result = new DoubleWritable();
    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
}
 
Example 13
Source File: TileX2LonUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2) {
        throw new UDFArgumentException("_FUNC_ takes exactly 2 arguments: " + argOIs.length);
    }
    this.xOI = HiveUtils.asIntegerOI(argOIs[0]);
    this.zoomOI = HiveUtils.asIntegerOI(argOIs[1]);

    this.result = new DoubleWritable();
    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
}
 
Example 14
Source File: TileY2LatUDF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 2) {
        throw new UDFArgumentException("_FUNC_ takes exactly 2 arguments: " + argOIs.length);
    }
    this.yOI = HiveUtils.asIntegerOI(argOIs[0]);
    this.zoomOI = HiveUtils.asIntegerOI(argOIs[1]);

    this.result = new DoubleWritable();
    return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
}
 
Example 15
Source File: FMPredictGenericUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
void merge(final double o_ret, @Nullable final Object o_sumVjXj,
        @Nullable final Object o_sumV2X2,
        @Nonnull final StandardListObjectInspector sumVjXjOI,
        @Nonnull final StandardListObjectInspector sumV2X2OI) throws HiveException {
    this.ret += o_ret;
    if (o_sumVjXj == null) {
        return;
    }

    if (o_sumV2X2 == null) {//sanity check
        throw new HiveException("o_sumV2X2 should not be null");
    }

    final int factors = sumVjXjOI.getListLength(o_sumVjXj);
    if (sumVjXj == null) {
        this.sumVjXj = new double[factors];
        this.sumV2X2 = new double[factors];
    } else if (sumVjXj.length != factors) {//sanity check
        throw new HiveException("Mismatch in the number of factors");
    }

    final WritableDoubleObjectInspector doubleOI =
            PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    for (int f = 0; f < factors; f++) {
        Object o1 = sumVjXjOI.getListElement(o_sumVjXj, f);
        Object o2 = sumV2X2OI.getListElement(o_sumV2X2, f);
        double d1 = doubleOI.get(o1);
        double d2 = doubleOI.get(o2);
        sumVjXj[f] += d1;
        sumV2X2[f] += d2;
    }
}
 
Example 16
Source File: FMPredictGenericUDAF.java    From incubator-hivemall with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector init(Mode mode, ObjectInspector[] parameters) throws HiveException {
    assert (parameters.length == 3);
    super.init(mode, parameters);

    // initialize input
    if (mode == Mode.PARTIAL1 || mode == Mode.COMPLETE) {// from original data
        this.wOI = HiveUtils.asDoubleCompatibleOI(parameters, 0);
        this.vOI = HiveUtils.asListOI(parameters, 1);
        this.vElemOI = HiveUtils.asDoubleCompatibleOI(vOI.getListElementObjectInspector());
        this.xOI = HiveUtils.asDoubleCompatibleOI(parameters, 2);
    } else {// from partial aggregation
        StructObjectInspector soi = (StructObjectInspector) parameters[0];
        this.internalMergeOI = soi;
        this.retField = soi.getStructFieldRef("ret");
        this.sumVjXjField = soi.getStructFieldRef("sumVjXj");
        this.sumV2X2Field = soi.getStructFieldRef("sumV2X2");
        this.retOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
        this.sumVjXjOI = ObjectInspectorFactory.getStandardListObjectInspector(
            PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
        this.sumV2X2OI = ObjectInspectorFactory.getStandardListObjectInspector(
            PrimitiveObjectInspectorFactory.writableDoubleObjectInspector);
    }

    // initialize output
    final ObjectInspector outputOI;
    if (mode == Mode.PARTIAL1 || mode == Mode.PARTIAL2) {// terminatePartial
        outputOI = internalMergeOI();
    } else {
        outputOI = PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    }
    return outputOI;
}
 
Example 17
Source File: TreePredictUDF.java    From incubator-hivemall with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 3 && argOIs.length != 4) {
        showHelp("tree_predict takes 3 or 4 arguments");
    }

    this.modelOI = HiveUtils.asStringOI(argOIs, 1);
    ListObjectInspector listOI = HiveUtils.asListOI(argOIs, 2);
    this.featureListOI = listOI;
    ObjectInspector elemOI = listOI.getListElementObjectInspector();
    if (HiveUtils.isNumberOI(elemOI)) {
        this.featureElemOI = HiveUtils.asDoubleCompatibleOI(elemOI);
        this.denseInput = true;
    } else if (HiveUtils.isStringOI(elemOI)) {
        this.featureElemOI = HiveUtils.asStringOI(elemOI);
        this.denseInput = false;
    } else {
        throw new UDFArgumentException(
            "tree_predict takes array<double> or array<string> for the second argument: "
                    + listOI.getTypeName());
    }

    if (argOIs.length == 4) {
        ObjectInspector argOI3 = argOIs[3];
        if (HiveUtils.isConstBoolean(argOI3)) {
            this.classification = HiveUtils.getConstBoolean(argOI3);
        } else if (HiveUtils.isConstString(argOI3)) {
            String opts = HiveUtils.getConstString(argOI3);
            processOptions(opts);
        } else {
            throw new UDFArgumentException(
                "tree_predict expects <const boolean> or <const string> for the fourth argument: "
                        + argOI3.getTypeName());
        }
    } else {
        this.classification = false;
    }

    if (classification) {
        List<String> fieldNames = new ArrayList<String>(2);
        List<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(2);
        fieldNames.add("value");
        fieldOIs.add(PrimitiveObjectInspectorFactory.writableIntObjectInspector);
        fieldNames.add("posteriori");
        fieldOIs.add(ObjectInspectorFactory.getStandardListObjectInspector(
            PrimitiveObjectInspectorFactory.writableDoubleObjectInspector));
        return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
    } else {
        return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
    }
}
 
Example 18
Source File: OrcLazyObjectInspectorUtils.java    From hive-dwrf with Apache License 2.0 4 votes vote down vote up
public static ObjectInspector createWritableObjectInspector(TypeInfo info) {
  switch (info.getCategory()) {
    case PRIMITIVE:
      switch (((PrimitiveTypeInfo) info).getPrimitiveCategory()) {
        case FLOAT:
          return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
        case DOUBLE:
          return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
        case BOOLEAN:
          return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        case BYTE:
          return PrimitiveObjectInspectorFactory.writableByteObjectInspector;
        case SHORT:
          return PrimitiveObjectInspectorFactory.writableShortObjectInspector;
        case INT:
          return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
        case LONG:
          return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
        case BINARY:
          return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
        case STRING:
          return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
        case TIMESTAMP:
          return PrimitiveObjectInspectorFactory.javaTimestampObjectInspector;
        default:
          throw new IllegalArgumentException("Unknown primitive type " +
            ((PrimitiveTypeInfo) info).getPrimitiveCategory());
      }
    case STRUCT:
      return new OrcStruct.OrcStructInspector((StructTypeInfo) info);
    case UNION:
      return new OrcUnion.OrcUnionObjectInspector((UnionTypeInfo) info);
    case MAP:
      return new OrcStruct.OrcMapObjectInspector((MapTypeInfo) info);
    case LIST:
      return new OrcStruct.OrcListObjectInspector((ListTypeInfo) info);
    default:
      throw new IllegalArgumentException("Unknown type " +
        info.getCategory());
  }
}
 
Example 19
Source File: MDSObjectInspectorFactory.java    From multiple-dimension-spread with Apache License 2.0 4 votes vote down vote up
public static ObjectInspector craeteObjectInspectorFromTypeInfo( final TypeInfo typeInfo ){
  switch ( typeInfo.getCategory() ){
    case STRUCT:
      return new MDSStructObjectInspector( (StructTypeInfo)typeInfo );
    case MAP:
      return new MDSMapObjectInspector( (MapTypeInfo)typeInfo );
    case LIST:
      return new MDSListObjectInspector( (ListTypeInfo)typeInfo );
    case UNION:
      UnionTypeInfo unionTypeInfo = (UnionTypeInfo)typeInfo;
      List<ObjectInspector> unionList = new ArrayList<ObjectInspector>();
      for( TypeInfo childTypeInfo : unionTypeInfo.getAllUnionObjectTypeInfos() ){
        unionList.add( craeteObjectInspectorFromTypeInfo( childTypeInfo ) );
      }
      return ObjectInspectorFactory.getStandardUnionObjectInspector( unionList );
    case PRIMITIVE:
      PrimitiveTypeInfo primitiveTypeInfo = (PrimitiveTypeInfo)typeInfo;
      switch( primitiveTypeInfo.getPrimitiveCategory() ){
        case STRING:
          return PrimitiveObjectInspectorFactory.writableStringObjectInspector;
        case BINARY:
          return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
        case BOOLEAN:
          return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
        case BYTE:
          return PrimitiveObjectInspectorFactory.writableByteObjectInspector;
        case DOUBLE:
          return PrimitiveObjectInspectorFactory.writableDoubleObjectInspector;
        case FLOAT:
          return PrimitiveObjectInspectorFactory.writableFloatObjectInspector;
        case INT:
          return PrimitiveObjectInspectorFactory.writableIntObjectInspector;
        case LONG:
          return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
        case SHORT:
          return PrimitiveObjectInspectorFactory.writableShortObjectInspector;

        case DATE:
        case DECIMAL:
        case TIMESTAMP:
        case VOID:
        default:
        throw new UnsupportedOperationException( "Unknown primitive category " + primitiveTypeInfo.getPrimitiveCategory() );
      }
    default:
      throw new UnsupportedOperationException( "Unknown category " + typeInfo.getCategory() );
  }
}