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

The following examples show how to use org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectInspectorFactory#writableLongObjectInspector() . 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
/**
*
* Initialize HiveUDF and create object inspectors. It requires that the argument length is = 1 and that the ObjectInspector of arguments[0] is of type StructObjectInspector
*
* @param arguments array of length 1 containing one StructObjectInspector
*
* @return ObjectInspector that is able to parse the result of the evaluate method of the UDF (BinaryWritable)
*
* @throws org.apache.hadoop.hive.ql.exec.UDFArgumentException in case the first argument is not of StructObjectInspector
* @throws org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in case the number of arguments is != 1
*
*/

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
	if (arguments==null) {
      		throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> ");
	}
  	if (arguments.length != 1) {
      		throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> ");
	}
	if (!(arguments[0] instanceof StructObjectInspector)) { 
		throw new UDFArgumentException("first argument must be a Struct containing a BitcoinTransaction");
	}
	this.soi = (StructObjectInspector)arguments[0];
	// these are only used for bitcointransaction structs exported to other formats, such as ORC
	this.wboi = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
	this.wioi = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
	this.wloi = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
	this.hdoi = PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector;
	// the UDF returns the hash value of a BitcoinTransaction as byte array
	return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
}
 
Example 2
/**
*
* Initialize HiveUDF and create object inspectors. It requires that the argument length is = 1 and that the ObjectInspector of arguments[0] is of type StructObjectInspector
*
* @param arguments array of length 1 containing one StructObjectInspector
*
* @return ObjectInspector that is able to parse the result of the evaluate method of the UDF (BinaryWritable)
*
* @throws org.apache.hadoop.hive.ql.exec.UDFArgumentException in case the first argument is not of StructObjectInspector
* @throws org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException in case the number of arguments is != 1
*
*/

@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
	if (arguments==null) {
      		throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> ");
	}
  	if (arguments.length != 1) {
      		throw new UDFArgumentLengthException("bitcoinTransactionHash only takes one argument: Struct<BitcoinTransaction> ");
	}
	if (!(arguments[0] instanceof StructObjectInspector)) { 
		throw new UDFArgumentException("first argument must be a Struct containing a BitcoinTransaction");
	}
	this.soi = (StructObjectInspector)arguments[0];
	// these are only used for bitcointransaction structs exported to other formats, such as ORC
	this.wboi = PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
	this.wioi = PrimitiveObjectInspectorFactory.writableIntObjectInspector;
	this.wloi = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
	this.wbyoi = PrimitiveObjectInspectorFactory.writableByteObjectInspector;
	this.hdoi = PrimitiveObjectInspectorFactory.javaHiveDecimalObjectInspector;
	// the UDF returns the hash value of a BitcoinTransaction as byte array
	return PrimitiveObjectInspectorFactory.writableBinaryObjectInspector;
}
 
Example 3
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
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 5
Source Project: incubator-hivemall   File: TileUDF.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException {
    if (argOIs.length != 3) {
        throw new UDFArgumentException("_FUNC_ takes exactly 3 arguments: " + argOIs.length);
    }
    this.latOI = HiveUtils.asDoubleCompatibleOI(argOIs[0]);
    this.lonOI = HiveUtils.asDoubleCompatibleOI(argOIs[1]);
    this.zoomOI = HiveUtils.asIntegerOI(argOIs[2]);

    this.result = new LongWritable();
    return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
 
Example 6
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 7
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 8
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() );
  }
}
 
Example 9
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_value_count(array, value) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_value_count, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    valueOI = arguments[VALUE_IDX];

    // Check if list element and value are of same type
    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
        throw new UDFArgumentTypeException(VALUE_IDX,
                "\"" + arrayElementOI.getTypeName() + "\""
                        + " expected at function array_value_count, but "
                        + "\"" + valueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(valueOI)) {
        throw new UDFArgumentException("The function array_value_count"
                + " does not support comparison for "
                + "\"" + valueOI.getTypeName() + "\""
                + " types");
    }

    result = new LongWritable(0L);

    return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
 
Example 10
@Override
public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    // Check if two arguments were passed
    if (arguments.length != ARG_COUNT) {
        throw new UDFArgumentLengthException(
                "The function array_position(array, value) takes exactly " + ARG_COUNT + " arguments.");
    }

    // Check if ARRAY_IDX argument is of category LIST
    if (!arguments[ARRAY_IDX].getCategory().equals(ObjectInspector.Category.LIST)) {
        throw new UDFArgumentTypeException(ARRAY_IDX,
                "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" "
                        + "expected at function array_position, but "
                        + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" "
                        + "is found");
    }

    arrayOI = (ListObjectInspector) arguments[ARRAY_IDX];
    arrayElementOI = arrayOI.getListElementObjectInspector();

    valueOI = arguments[VALUE_IDX];

    // Check if list element and value are of same type
    if (!ObjectInspectorUtils.compareTypes(arrayElementOI, valueOI)) {
        throw new UDFArgumentTypeException(VALUE_IDX,
                "\"" + arrayElementOI.getTypeName() + "\""
                        + " expected at function array_position, but "
                        + "\"" + valueOI.getTypeName() + "\""
                        + " is found");
    }

    // Check if the comparison is supported for this type
    if (!ObjectInspectorUtils.compareSupported(valueOI)) {
        throw new UDFArgumentException("The function array_position"
                + " does not support comparison for "
                + "\"" + valueOI.getTypeName() + "\""
                + " types");
    }

    result = new LongWritable(0L);

    return PrimitiveObjectInspectorFactory.writableLongObjectInspector;
}
 
Example 11
@Test
public void testWritableLongFeature() throws Exception {
    List<LongWritable> x = Arrays.asList(new LongWritable(111L), new LongWritable(222L));
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    testFeature(x, featureOI, LongWritable.class, Long.class);
}
 
Example 12
@Test
public void testWritableLongFeature() throws Exception {
    List<LongWritable> x = Arrays.asList(new LongWritable(111L), new LongWritable(222L));
    ObjectInspector featureOI = PrimitiveObjectInspectorFactory.writableLongObjectInspector;
    testFeature(x, featureOI, LongWritable.class, Long.class);
}
 
Example 13
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());
  }
}