Java Code Examples for org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector#getListElementObjectInspector()
The following examples show how to use
org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector#getListElementObjectInspector() .
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: ArrayFlattenUDF.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Override public ObjectInspector initialize(ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 1) { throw new UDFArgumentException( "array_flatten expects exactly one argument: " + argOIs.length); } this.listOI = HiveUtils.asListOI(argOIs[0]); ObjectInspector listElemOI = listOI.getListElementObjectInspector(); if (listElemOI.getCategory() != Category.LIST) { throw new UDFArgumentException( "array_flatten takes array of array for the argument: " + listOI.toString()); } ListObjectInspector nestedListOI = HiveUtils.asListOI(listElemOI); ObjectInspector elemOI = nestedListOI.getListElementObjectInspector(); return ObjectInspectorFactory.getStandardListObjectInspector( ObjectInspectorUtils.getStandardObjectInspector(elemOI, ObjectInspectorCopyOption.WRITABLE)); }
Example 2
Source File: ArrayUtils.java From hive-third-functions with Apache License 2.0 | 6 votes |
public static IntComparator IntArrayCompare(final Object array, final ListObjectInspector arrayOI) { return new AbstractIntComparator() { @Override public int compare(int left, int right) { ObjectInspector arrayElementOI = arrayOI.getListElementObjectInspector(); Object leftArrayElement = arrayOI.getListElement(array, left); Object rightArrayElement = arrayOI.getListElement(array, right); if (leftArrayElement == null && rightArrayElement == null) { return 0; } if (leftArrayElement == null) { return -1; } if (rightArrayElement == null) { return 1; } int result = ObjectInspectorUtils.compare(leftArrayElement, arrayElementOI, rightArrayElement, arrayElementOI); return result; } }; }
Example 3
Source File: BitcoinTransactionHashUDF.java From hadoopcryptoledger with Apache License 2.0 | 6 votes |
/** * Read list of Bitcoin transaction outputs from a table in Hive in any format (e.g. ORC, Parquet) * * @param loi ObjectInspector for processing the Object containing a list * @param listOfOutputsObject object containing the list of outputs to a Bitcoin Transaction * * @return a list of BitcoinTransactionOutputs * */ private List<BitcoinTransactionOutput> readListOfOutputsFromTable(ListObjectInspector loi, Object listOfOutputsObject) { int listLength=loi.getListLength(listOfOutputsObject); List<BitcoinTransactionOutput> result=new ArrayList<>(listLength); StructObjectInspector listOfOutputsElementObjectInspector = (StructObjectInspector)loi.getListElementObjectInspector(); for (int i=0;i<listLength;i++) { Object currentListOfOutputsObject = loi.getListElement(listOfOutputsObject,i); StructField valueSF = listOfOutputsElementObjectInspector.getStructFieldRef("value"); StructField txoutscriptlengthSF = listOfOutputsElementObjectInspector.getStructFieldRef("txoutscriptlength"); StructField txoutscriptSF = listOfOutputsElementObjectInspector.getStructFieldRef("txoutscript"); if ((valueSF==null) || (txoutscriptlengthSF==null) || (txoutscriptSF==null)) { LOG.warn("Invalid BitcoinTransactionOutput detected at position "+i); return new ArrayList<>(); } HiveDecimal currentValue=hdoi.getPrimitiveJavaObject(listOfOutputsElementObjectInspector.getStructFieldData(currentListOfOutputsObject,valueSF)); byte[] currentTxOutScriptLength=wboi.getPrimitiveJavaObject(listOfOutputsElementObjectInspector.getStructFieldData(currentListOfOutputsObject,txoutscriptlengthSF)); byte[] currentTxOutScript=wboi.getPrimitiveJavaObject(listOfOutputsElementObjectInspector.getStructFieldData(currentListOfOutputsObject,txoutscriptSF)); BitcoinTransactionOutput currentBitcoinTransactionOutput = new BitcoinTransactionOutput(currentValue.bigDecimalValue().toBigIntegerExact(),currentTxOutScriptLength,currentTxOutScript); result.add(currentBitcoinTransactionOutput); } return result; }
Example 4
Source File: XGBoostOnlinePredictUDTF.java From incubator-hivemall with Apache License 2.0 | 6 votes |
@Override public StructObjectInspector initialize(@Nonnull ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 4 && argOIs.length != 5) { showHelp("Invalid argment length=" + argOIs.length); } processOptions(argOIs); this.rowIdOI = HiveUtils.asPrimitiveObjectInspector(argOIs, 0); ListObjectInspector listOI = HiveUtils.asListOI(argOIs, 1); this.featureListOI = listOI; ObjectInspector elemOI = listOI.getListElementObjectInspector(); if (HiveUtils.isNumberOI(elemOI)) { this.featureElemOI = HiveUtils.asDoubleCompatibleOI(elemOI); this.denseFeatures = true; } else if (HiveUtils.isStringOI(elemOI)) { this.denseFeatures = false; } else { throw new UDFArgumentException( "Expected array<string|double> for the 2nd argment but got an unexpected features type: " + listOI.getTypeName()); } this.modelIdOI = HiveUtils.asStringOI(argOIs, 2); this.modelOI = HiveUtils.asStringOI(argOIs, 3); return getReturnOI(rowIdOI); }
Example 5
Source File: DynamoDBDataParser.java From emr-dynamodb-connector with Apache License 2.0 | 6 votes |
/** * This method currently supports BinarySet data type of DynamoDB */ public static List<ByteBuffer> getByteBuffers(Object data, ObjectInspector objectInspector, String ddType) { ListObjectInspector listObjectInspector = (ListObjectInspector) objectInspector; List<?> dataList = listObjectInspector.getList(data); if (dataList == null) { return null; } ObjectInspector itemObjectInspector = listObjectInspector.getListElementObjectInspector(); List<ByteBuffer> itemList = new ArrayList<>(); for (Object dataItem : dataList) { if (dataItem == null) { throw new NullPointerException("Null element found in list: " + dataList); } if (ddType.equals(DynamoDBTypeConstants.BINARY_SET)) { itemList.add(getByteBuffer(dataItem, itemObjectInspector)); } else { throw new IllegalArgumentException("Expecting BinarySet type: " + ddType); } } return itemList; }
Example 6
Source File: DynamoDBDataParser.java From emr-dynamodb-connector with Apache License 2.0 | 6 votes |
public static List<AttributeValue> getListAttribute(Object data, ObjectInspector objectInspector, boolean nullSerialization) { ListObjectInspector listObjectInspector = (ListObjectInspector) objectInspector; List<?> dataList = listObjectInspector.getList(data); if (dataList == null) { return null; } ObjectInspector itemObjectInspector = listObjectInspector.getListElementObjectInspector(); HiveDynamoDBType itemType = HiveDynamoDBTypeFactory.getTypeObjectFromHiveType(itemObjectInspector); List<AttributeValue> itemList = new ArrayList<>(); for (Object dataItem : dataList) { AttributeValue item = dataItem == null ? getNullAttribute(nullSerialization) : itemType.getDynamoDBData(dataItem, itemObjectInspector, nullSerialization); if (item == null) { throw new NullPointerException("Null element found in list: " + dataList); } itemList.add(item); } return itemList; }
Example 7
Source File: TestDataWritableWriter.java From presto with Apache License 2.0 | 5 votes |
/** * It writes a list type and its array elements to the Parquet RecordConsumer. * This is called when the original type (LIST) is detected by writeValue()/ * This function assumes the following schema: * optional group arrayCol (LIST) { * repeated group array { * optional TYPE array_element; * } * } * * @param value The object that contains the array values. * @param inspector The object inspector used to get the correct value type. * @param type Type that contains information about the group (LIST) schema. */ private void writeArray(Object value, ListObjectInspector inspector, GroupType type) { // Get the internal array structure GroupType repeatedType = type.getType(0).asGroupType(); recordConsumer.startGroup(); List<?> arrayValues = inspector.getList(value); if (!arrayValues.isEmpty()) { recordConsumer.startField(repeatedType.getName(), 0); ObjectInspector elementInspector = inspector.getListElementObjectInspector(); Type elementType = repeatedType.getType(0); String elementName = elementType.getName(); for (Object element : arrayValues) { recordConsumer.startGroup(); if (element != null) { recordConsumer.startField(elementName, 0); writeValue(element, elementInspector, elementType); recordConsumer.endField(elementName, 0); } recordConsumer.endGroup(); } recordConsumer.endField(repeatedType.getName(), 0); } recordConsumer.endGroup(); }
Example 8
Source File: UDFMapBuild.java From hive-third-functions with Apache License 2.0 | 5 votes |
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { // Check if two arguments were passed if (arguments.length != ARG_COUNT) { throw new UDFArgumentLengthException( "The function map_build(array, array) takes exactly " + ARG_COUNT + " arguments."); } // Check if two argument is of category LIST for (int i = 0; i < 2; i++) { if (!arguments[i].getCategory().equals(ObjectInspector.Category.LIST)) { throw new UDFArgumentTypeException(i, "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" " + "expected at function map_build, but " + "\"" + arguments[i].getTypeName() + "\" " + "is found"); } } keyArrayOI = (ListObjectInspector) arguments[0]; valueArrayOI = (ListObjectInspector) arguments[1]; ObjectInspector mapKeyOI = keyArrayOI.getListElementObjectInspector(); ObjectInspector mapValueOI = valueArrayOI.getListElementObjectInspector(); return ObjectInspectorFactory.getStandardMapObjectInspector(mapKeyOI, mapValueOI); }
Example 9
Source File: HiveJsonStructReader.java From incubator-hivemall with Apache License 2.0 | 5 votes |
private Object parseList(JsonParser parser, ListObjectInspector oi) throws JsonParseException, IOException, SerDeException { List<Object> ret = new ArrayList<>(); if (parser.getCurrentToken() == JsonToken.VALUE_NULL) { parser.nextToken(); return null; } if (parser.getCurrentToken() != JsonToken.START_ARRAY) { throw new SerDeException("array expected"); } ObjectInspector eOI = oi.getListElementObjectInspector(); JsonToken currentToken = parser.nextToken(); try { while (currentToken != null && currentToken != JsonToken.END_ARRAY) { ret.add(parseDispatcher(parser, eOI)); currentToken = parser.getCurrentToken(); } } catch (Exception e) { throw new SerDeException("array: " + e.getMessage(), e); } currentToken = parser.nextToken(); return ret; }
Example 10
Source File: UDFArraySlice.java From hive-third-functions with Apache License 2.0 | 5 votes |
@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_slice(array, start, length) 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_slice, but " + "\"" + arguments[ARRAY_IDX].getTypeName() + "\" " + "is found"); } arrayOI = (ListObjectInspector) arguments[ARRAY_IDX]; arrayElementOI = arrayOI.getListElementObjectInspector(); ObjectInspector expectOI = PrimitiveObjectInspectorFactory.writableIntObjectInspector; // Check if value and expect are of same type for (int i = 1; i < 3; i++) { if (!ObjectInspectorUtils.compareTypes(expectOI, arguments[i])) { throw new UDFArgumentTypeException(i, "\"" + expectOI.getTypeName() + "\"" + " expected at function array_slice, but " + "\"" + arguments[i].getTypeName() + "\"" + " is found"); } } return ObjectInspectorFactory.getStandardListObjectInspector(arrayElementOI); }
Example 11
Source File: DynamoDBDataParser.java From emr-dynamodb-connector with Apache License 2.0 | 5 votes |
public static Object getListObject(List<AttributeValue> data, ObjectInspector objectInspector) { ListObjectInspector listOI = (ListObjectInspector) objectInspector; ObjectInspector elementOI = listOI.getListElementObjectInspector(); HiveDynamoDBType elementType = HiveDynamoDBTypeFactory.getTypeObjectFromHiveType(elementOI); List<Object> values = new ArrayList<>(); for (AttributeValue av : data) { values.add(elementType.getHiveData(av, elementOI)); } return values; }
Example 12
Source File: UDFArrayMax.java From hive-third-functions with Apache License 2.0 | 5 votes |
@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_max(array) takes exactly " + ARG_COUNT + "arguments."); } // Check if two argument is of category LIST if (!arguments[0].getCategory().equals(ObjectInspector.Category.LIST)) { throw new UDFArgumentTypeException(0, "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" " + "expected at function array_max, but " + "\"" + arguments[0].getTypeName() + "\" " + "is found"); } arrayOI = (ListObjectInspector) arguments[0]; arrayElementOI = arrayOI.getListElementObjectInspector(); // Check if the comparison is supported for this type if (!ObjectInspectorUtils.compareSupported(arrayElementOI)) { throw new UDFArgumentException("The function array_max" + " does not support comparison for " + "\"" + arrayElementOI.getTypeName() + "\"" + " types"); } return arrayElementOI; }
Example 13
Source File: ArrayIntersectUDF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public ObjectInspector initialize(@Nonnull ObjectInspector[] argOIs) throws UDFArgumentException { final int argLength = argOIs.length; if (argLength < 2) { throw new UDFArgumentLengthException( "Expecting at least two arrays as arguments: " + argLength); } ListObjectInspector[] argListOIs = new ListObjectInspector[argLength]; ListObjectInspector arg0ListOI = HiveUtils.asListOI(argOIs[0]); ObjectInspector arg0ElemOI = arg0ListOI.getListElementObjectInspector(); argListOIs[0] = arg0ListOI; for (int i = 1; i < argLength; i++) { ListObjectInspector listOI = HiveUtils.asListOI(argOIs[i]); if (!ObjectInspectorUtils.compareTypes(listOI.getListElementObjectInspector(), arg0ElemOI)) { throw new UDFArgumentException( "Array types does not match: " + arg0ElemOI.getTypeName() + " != " + listOI.getListElementObjectInspector().getTypeName()); } argListOIs[i] = listOI; } this.argListOIs = argListOIs; this.result = new ArrayList<Object>(); return ObjectInspectorUtils.getStandardObjectInspector(arg0ListOI); }
Example 14
Source File: XGBoostTrainUDTF.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Override public StructObjectInspector initialize(@Nonnull ObjectInspector[] argOIs) throws UDFArgumentException { if (argOIs.length != 2 && argOIs.length != 3) { showHelp("Invalid argment length=" + argOIs.length); } processOptions(argOIs); ListObjectInspector listOI = HiveUtils.asListOI(argOIs, 0); ObjectInspector elemOI = listOI.getListElementObjectInspector(); this.featureListOI = listOI; if (HiveUtils.isNumberOI(elemOI)) { this.featureElemOI = HiveUtils.asDoubleCompatibleOI(elemOI); this.denseInput = true; this.matrixBuilder = new DenseDMatrixBuilder(8192); } else if (HiveUtils.isStringOI(elemOI)) { this.featureElemOI = HiveUtils.asStringOI(elemOI); this.denseInput = false; this.matrixBuilder = new SparseDMatrixBuilder(8192); } else { throw new UDFArgumentException( "train_xgboost takes array<double> or array<string> for the first argument: " + listOI.getTypeName()); } this.targetOI = HiveUtils.asDoubleCompatibleOI(argOIs, 1); this.labels = new FloatArrayList(1024); final List<String> fieldNames = new ArrayList<>(2); final List<ObjectInspector> fieldOIs = new ArrayList<>(2); fieldNames.add("model_id"); fieldOIs.add(PrimitiveObjectInspectorFactory.javaStringObjectInspector); fieldNames.add("model"); fieldOIs.add(PrimitiveObjectInspectorFactory.writableStringObjectInspector); return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); }
Example 15
Source File: BitcoinTransactionHashUDF.java From hadoopcryptoledger with Apache License 2.0 | 5 votes |
/** * Read list of Bitcoin transaction inputs from a table in Hive in any format (e.g. ORC, Parquet) * * @param loi ObjectInspector for processing the Object containing a list * @param listOfInputsObject object containing the list of inputs to a Bitcoin Transaction * * @return a list of BitcoinTransactionInputs * */ private List<BitcoinTransactionInput> readListOfInputsFromTable(ListObjectInspector loi, Object listOfInputsObject) { int listLength=loi.getListLength(listOfInputsObject); List<BitcoinTransactionInput> result = new ArrayList<>(listLength); StructObjectInspector listOfInputsElementObjectInspector = (StructObjectInspector)loi.getListElementObjectInspector(); for (int i=0;i<listLength;i++) { Object currentlistofinputsObject = loi.getListElement(listOfInputsObject,i); StructField prevtransactionhashSF = listOfInputsElementObjectInspector.getStructFieldRef("prevtransactionhash"); StructField previoustxoutindexSF = listOfInputsElementObjectInspector.getStructFieldRef("previoustxoutindex"); StructField txinscriptlengthSF = listOfInputsElementObjectInspector.getStructFieldRef("txinscriptlength"); StructField txinscriptSF = listOfInputsElementObjectInspector.getStructFieldRef("txinscript"); StructField seqnoSF = listOfInputsElementObjectInspector.getStructFieldRef("seqno"); boolean prevFieldsNull = (prevtransactionhashSF==null) || (previoustxoutindexSF==null); boolean inFieldsNull = (txinscriptlengthSF==null) || (txinscriptSF==null); boolean otherAttribNull = seqnoSF==null; if (prevFieldsNull || inFieldsNull || otherAttribNull) { LOG.warn("Invalid BitcoinTransactionInput detected at position "+i); return new ArrayList<>(); } byte[] currentPrevTransactionHash = wboi.getPrimitiveJavaObject(listOfInputsElementObjectInspector.getStructFieldData(currentlistofinputsObject,prevtransactionhashSF)); long currentPreviousTxOutIndex = wloi.get(listOfInputsElementObjectInspector.getStructFieldData(currentlistofinputsObject,previoustxoutindexSF)); byte[] currentTxInScriptLength= wboi.getPrimitiveJavaObject(listOfInputsElementObjectInspector.getStructFieldData(currentlistofinputsObject,txinscriptlengthSF)); byte[] currentTxInScript= wboi.getPrimitiveJavaObject(listOfInputsElementObjectInspector.getStructFieldData(currentlistofinputsObject,txinscriptSF)); long currentSeqNo = wloi.get(listOfInputsElementObjectInspector.getStructFieldData(currentlistofinputsObject,seqnoSF)); BitcoinTransactionInput currentBitcoinTransactionInput = new BitcoinTransactionInput(currentPrevTransactionHash,currentPreviousTxOutIndex,currentTxInScriptLength,currentTxInScript,currentSeqNo); result.add(currentBitcoinTransactionInput); } return result; }
Example 16
Source File: UDFArrayContains.java From hive-third-functions with Apache License 2.0 | 4 votes |
@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_contains(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_contains, 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_contains, but " + "\"" + valueOI.getTypeName() + "\"" + " is found"); } // Check if the comparison is supported for this type if (!ObjectInspectorUtils.compareSupported(valueOI)) { throw new UDFArgumentException("The function array_contains" + " does not support comparison for " + "\"" + valueOI.getTypeName() + "\"" + " types"); } result = new BooleanWritable(false); return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
Example 17
Source File: UDFArrayValueCount.java From hive-third-functions with Apache License 2.0 | 4 votes |
@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 18
Source File: TreePredictUDF.java From incubator-hivemall with Apache License 2.0 | 4 votes |
@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 19
Source File: ArrayContains.java From Apache-Hive-Essentials-Second-Edition with MIT License | 4 votes |
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { // Check if two arguments were passed if (arguments.length != ARG_COUNT) { throw new UDFArgumentException( "The function " + FUNC_NAME + " accepts " + ARG_COUNT + " arguments."); } // Check if ARRAY_IDX argument is of category LIST if (!arguments[ARRAY_IDX].getCategory().equals(Category.LIST)) { throw new UDFArgumentTypeException(ARRAY_IDX, "\"" + org.apache.hadoop.hive.serde.serdeConstants.LIST_TYPE_NAME + "\" " + "expected at function ARRAY_CONTAINS, 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_CONTAINS, but " + "\"" + valueOI.getTypeName() + "\"" + " is found"); } // Check if the comparison is supported for this type if (!ObjectInspectorUtils.compareSupported(valueOI)) { throw new UDFArgumentException("The function " + FUNC_NAME + " does not support comparison for " + "\"" + valueOI.getTypeName() + "\"" + " types"); } result = new BooleanWritable(false); return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
Example 20
Source File: HiveArray.java From transport with BSD 2-Clause "Simplified" License | 4 votes |
public HiveArray(Object object, ObjectInspector objectInspector, StdFactory stdFactory) { super(stdFactory); _object = object; _listObjectInspector = (ListObjectInspector) objectInspector; _elementObjectInspector = _listObjectInspector.getListElementObjectInspector(); }