soi = (StructObjectInspector) parameters[0]; countTruesField = soi.getStructFieldRef("counttrues"); countTruesFieldOI = (WritableLongObjectInspector) countTruesField.getFieldObjectInspector(); countFalsesField = soi.getStructFieldRef("countfalses"); countFalsesFieldOI = (WritableLongObjectInspector) countFalsesField.getFieldObjectInspector(); countNullsField = soi.getStructFieldRef("countnulls"); countNullsFieldOI = (WritableLongObjectInspector) countNullsField.getFieldObjectInspector(); partialResult[1] = new LongWritable(0); partialResult[2] = new LongWritable(0); partialResult[3] = new LongWritable(0); result[3] = new LongWritable(0); return ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi);
protected static StructObjectInspector createSelectListOI(MatchPath evaluator, PTFInputDef inpDef) { StructObjectInspector inOI = inpDef.getOutputShape().getOI(); ArrayList<String> inputColumnNames = new ArrayList<String>(); ArrayList<String> selectListNames = new ArrayList<String>(); ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(); for(StructField f : inOI.getAllStructFieldRefs()) { String inputColName = evaluator.inputColumnNamesMap.get(f.getFieldName()); if ( inputColName != null ) { inputColumnNames.add(inputColName); selectListNames.add(f.getFieldName()); fieldOIs.add(f.getFieldObjectInspector()); } } StandardListObjectInspector pathAttrOI = ObjectInspectorFactory.getStandardListObjectInspector( ObjectInspectorFactory.getStandardStructObjectInspector(inputColumnNames, fieldOIs)); ArrayList<ObjectInspector> selectFieldOIs = new ArrayList<ObjectInspector>(); selectFieldOIs.addAll(fieldOIs); selectFieldOIs.add(pathAttrOI); selectListNames.add(MatchPath.PATHATTR_NAME); return ObjectInspectorFactory.getStandardStructObjectInspector( selectListNames, selectFieldOIs); }
private ObjectInspector convertMap(ObjectInspector inspector, AtomicBoolean foundUnion) { MapObjectInspector mapOI = (MapObjectInspector) inspector; ObjectInspector keyOI = convert(mapOI.getMapKeyObjectInspector(), foundUnion); ObjectInspector valueOI = convert(mapOI.getMapValueObjectInspector(), foundUnion); return ObjectInspectorFactory.getStandardMapObjectInspector(keyOI, valueOI); }
if(outerInputOI.getListElementObjectInspector().getCategory() == ObjectInspector.Category.LIST) { innerInputOI = (StandardListObjectInspector) outerInputOI.getListElementObjectInspector(); inputOI = (PrimitiveObjectInspector) innerInputOI.getListElementObjectInspector(); } else { inputOI = (PrimitiveObjectInspector) outerInputOI.getListElementObjectInspector(); innerInputOI = null; return ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.writableStringObjectInspector); } else { foi.add(ObjectInspectorFactory.getStandardListObjectInspector( PrimitiveObjectInspectorFactory.writableStringObjectInspector)); foi.add(PrimitiveObjectInspectorFactory.writableDoubleObjectInspector); fname.add("ngram"); fname.add("estfrequency"); return ObjectInspectorFactory.getStandardListObjectInspector( ObjectInspectorFactory.getStandardStructObjectInspector(fname, foi) );
result = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector( ListObjectInspector loi = (ListObjectInspector) oi; result = ObjectInspectorFactory .getStandardListObjectInspector(getStandardObjectInspector(loi .getListElementObjectInspector(), objectInspectorOption)); break; result = ObjectInspectorFactory.getStandardMapObjectInspector( getStandardObjectInspector(moi.getMapKeyObjectInspector(), objectInspectorOption), getStandardObjectInspector(moi .getMapValueObjectInspector(), objectInspectorOption)); break; result = ObjectInspectorFactory.getStandardStructObjectInspector( fieldNames, fieldObjectInspectors); break; ois.add(getStandardObjectInspector(eoi, objectInspectorOption)); result = ObjectInspectorFactory.getStandardUnionObjectInspector(ois); break;
@Override public ObjectInspector initialize(ObjectInspector[] arg0) throws UDFArgumentException { ObjectInspector first = arg0[0]; if (first.getCategory() == Category.LIST) { listInspector = (ListObjectInspector) first; } else { throw new UDFArgumentException(" Expecting an array and an int as arguments "); } ObjectInspector second = arg0[1]; if (second.getCategory() == Category.PRIMITIVE) { PrimitiveObjectInspector secondPrim = (PrimitiveObjectInspector) second; if (secondPrim.getPrimitiveCategory() == PrimitiveCategory.INT) { intInspector = (IntObjectInspector) second; } else { throw new UDFArgumentException(" Expecting an array and an int as arguments "); } } else { throw new UDFArgumentException(" Expecting an array and an int as arguments "); } returnInspector = ObjectInspectorFactory.getStandardListObjectInspector( listInspector.getListElementObjectInspector()); return returnInspector; }
@Override public StructObjectInspector initialize(ObjectInspector[] args) throws UDFArgumentException { if (args.length != 1) { throw new UDFArgumentException("explode() takes only one argument"); } ArrayList<String> fieldNames = new ArrayList<String>(); ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(); switch (args[0].getCategory()) { case LIST: inputOI = args[0]; fieldNames.add("col"); fieldOIs.add(((ListObjectInspector)inputOI).getListElementObjectInspector()); break; case MAP: inputOI = args[0]; fieldNames.add("key"); fieldNames.add("value"); fieldOIs.add(((MapObjectInspector)inputOI).getMapKeyObjectInspector()); fieldOIs.add(((MapObjectInspector)inputOI).getMapValueObjectInspector()); break; default: throw new UDFArgumentException("explode() takes an array or a map as a parameter"); } return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); }
@Override public StructObjectInspector initialize(ObjectInspector[] args) throws UDFArgumentException { if (args.length != 1) { throw new UDFArgumentException("posexplode() takes only one argument"); } if (args[0].getCategory() != ObjectInspector.Category.LIST) { throw new UDFArgumentException("posexplode() takes an array as a parameter"); } listOI = (ListObjectInspector) args[0]; ArrayList<String> fieldNames = new ArrayList<String>(); ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(); fieldNames.add("pos"); fieldNames.add("val"); fieldOIs.add(PrimitiveObjectInspectorFactory .getPrimitiveJavaObjectInspector(PrimitiveCategory.INT)); fieldOIs.add(listOI.getListElementObjectInspector()); return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { GenericUDFUtils.ReturnObjectInspectorResolver returnOIResolver; returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true); checkArgsSize(arguments, 1, 1); switch(arguments[0].getCategory()) { case LIST: if(!((ListObjectInspector)(arguments[0])).getListElementObjectInspector() .getCategory().equals(ObjectInspector.Category.UNION)) { break; } default: throw new UDFArgumentTypeException(0, "Argument 1" + " of function SORT_ARRAY must be " + serdeConstants.LIST_TYPE_NAME + ", and element type should be either primitive, list, struct, or map, " + "but " + arguments[0].getTypeName() + " was found."); } ObjectInspector elementObjectInspector = ((ListObjectInspector)(arguments[0])).getListElementObjectInspector(); argumentOIs = arguments; converters = new Converter[arguments.length]; ObjectInspector returnOI = returnOIResolver.get(elementObjectInspector); converters[0] = ObjectInspectorConverters.getConverter(elementObjectInspector, returnOI); return ObjectInspectorFactory.getStandardListObjectInspector(returnOI); }
@Override protected void initializeOp(Configuration hconf) throws HiveException { super.initializeOp(hconf); ArrayList<ObjectInspector> ois = new ArrayList<ObjectInspector>(); ArrayList<String> fieldNames = conf.getOutputInternalColNames(); // The output of the lateral view join will be the columns from the select // parent, followed by the column from the UDTF parent StructObjectInspector soi = (StructObjectInspector) inputObjInspectors[SELECT_TAG]; List<? extends StructField> sfs = soi.getAllStructFieldRefs(); for (StructField sf : sfs) { ois.add(sf.getFieldObjectInspector()); } soi = (StructObjectInspector) inputObjInspectors[UDTF_TAG]; sfs = soi.getAllStructFieldRefs(); for (StructField sf : sfs) { ois.add(sf.getFieldObjectInspector()); } outputObjInspector = ObjectInspectorFactory .getStandardStructObjectInspector(fieldNames, ois); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentException("Usage : map_key_values( map) "); } if (!arguments[0].getCategory().equals(Category.MAP)) { throw new UDFArgumentException("Usage : map_key_values( map) "); } moi = (MapObjectInspector) arguments[0]; //// List<String> structFieldNames = new ArrayList<String>(); List<ObjectInspector> structFieldObjectInspectors = new ArrayList<ObjectInspector>(); structFieldNames.add("key"); structFieldObjectInspectors.add(moi.getMapKeyObjectInspector()); structFieldNames.add("value"); structFieldObjectInspectors.add(moi.getMapValueObjectInspector()); ObjectInspector keyOI = ObjectInspectorFactory.getStandardStructObjectInspector(structFieldNames, structFieldObjectInspectors); ObjectInspector arrayOI = ObjectInspectorFactory.getStandardListObjectInspector(keyOI); return arrayOI; }
@Override public ObjectInspector initialize(ObjectInspector rowInspector) throws HiveException { leftInspector = leftEvaluator.initialize(rowInspector); if (expr.getIsList()) { structObjectInspector = (StructObjectInspector) ((ListObjectInspector) leftInspector) .getListElementObjectInspector(); } else { structObjectInspector = (StructObjectInspector) leftInspector; } field = structObjectInspector.getStructFieldRef(expr.getFieldName()); structFieldObjectInspector = field.getFieldObjectInspector(); if (expr.getIsList()) { resultObjectInspector = ObjectInspectorFactory .getStandardListObjectInspector(structFieldObjectInspector); } else { resultObjectInspector = structFieldObjectInspector; } return outputOI = resultObjectInspector; }
throw new UDFArgumentException("json_tuple() takes at least two arguments: " + "the json string and a path expression"); if (args[i].getCategory() != ObjectInspector.Category.PRIMITIVE || !args[i].getTypeName().equals(serdeConstants.STRING_TYPE_NAME)) { throw new UDFArgumentException("json_tuple()'s arguments have to be string type"); return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs);
public ObjectInspector init(Mode m, ObjectInspector[] parameters) throws HiveException { super.init(m, parameters); inputOI = (MapObjectInspector) parameters[0]; if (inputOI.getMapKeyObjectInspector().getCategory() != Category.PRIMITIVE) { throw new HiveException("Vector map keys must be a primitive."); } if (inputOI.getMapValueObjectInspector().getCategory() != Category.PRIMITIVE || !NumericUtil.isNumericCategory( ((PrimitiveObjectInspector) inputOI.getMapValueObjectInspector()).getPrimitiveCategory())) { throw new HiveException("Vector values must be numeric."); } stdMapOI = ObjectInspectorFactory. getStandardMapObjectInspector( ObjectInspectorUtils.getStandardObjectInspector(inputOI.getMapKeyObjectInspector(), ObjectInspectorUtils.ObjectInspectorCopyOption.JAVA), PrimitiveObjectInspectorFactory.javaDoubleObjectInspector); //// XXX make return type numeric type of input, //// not doubles... return stdMapOI; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { for (int idx = 0; idx < Math.min(arguments.length, 3); ++idx) { if (arguments[idx].getCategory() != Category.PRIMITIVE || PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector) arguments[idx]).getPrimitiveCategory()) != PrimitiveGrouping.STRING_GROUP) { throw new UDFArgumentException("All argument should be string/character type"); } } soi_text = ObjectInspectorConverters.getConverter(arguments[0], PrimitiveObjectInspectorFactory.javaStringObjectInspector); if (arguments.length > 1) { soi_de1 = ObjectInspectorConverters.getConverter(arguments[1], PrimitiveObjectInspectorFactory.javaStringObjectInspector); } if (arguments.length > 2) { soi_de2 = ObjectInspectorConverters.getConverter(arguments[2], PrimitiveObjectInspectorFactory.javaStringObjectInspector); } return ObjectInspectorFactory.getStandardMapObjectInspector( PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaStringObjectInspector); }
/** * Create a new struct object inspector for the list of struct fields, first removing the * prefix from the field name. * @param fields * @param prefixToRemove * @return */ private static ObjectInspector createStructFromFields(List<StructField> fields, String prefixToRemove) { int prefixLength = prefixToRemove.length() + 1; // also remove the '.' after the prefix ArrayList<String> fieldNames = new ArrayList<String>(); ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(); for (StructField field : fields) { fieldNames.add(field.getFieldName().substring(prefixLength)); fieldOIs.add(field.getFieldObjectInspector()); } return ObjectInspectorFactory.getStandardStructObjectInspector(fieldNames, fieldOIs); }
case PRIMITIVE: PrimitiveTypeInfo pti = (PrimitiveTypeInfo)ti; result = PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pti); break; case STRUCT: .getStandardStructObjectInspector(sti.getAllStructFieldNames(), ois); result = ObjectInspectorFactory.getStandardMapObjectInspector( PrimitiveObjectInspectorFactory .getPrimitiveJavaObjectInspector(PrimitiveObjectInspector.PrimitiveCategory.STRING), createObjectInspectorWorker(mti.getMapValueTypeInfo())); break; ListTypeInfo ati = (ListTypeInfo)ti; result = ObjectInspectorFactory .getStandardListObjectInspector(createObjectInspectorWorker(ati.getListElementTypeInfo())); break; case UNION: result = ObjectInspectorFactory.getStandardUnionObjectInspector(unionObjectInspectors); break; default:
switch (typeInfo.getCategory()) { case PRIMITIVE: { result = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector( (PrimitiveTypeInfo) typeInfo); break; .getListElementTypeInfo()); result = ObjectInspectorFactory .getStandardListObjectInspector(elementObjectInspector); break; ObjectInspector valueObjectInspector = getStandardWritableObjectInspectorFromTypeInfo(mapTypeInfo.getMapValueTypeInfo()); result = ObjectInspectorFactory.getStandardMapObjectInspector( keyObjectInspector, valueObjectInspector); break; .get(i))); result = ObjectInspectorFactory.getStandardStructObjectInspector( fieldNames, fieldObjectInspectors); break; .get(i))); result = ObjectInspectorFactory.getStandardUnionObjectInspector( fieldObjectInspectors); break;
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException("The function MAP_VALUES only accepts 1 argument."); } else if (!(arguments[0] instanceof MapObjectInspector)) { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" is expected at function MAP_VALUES, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } mapOI = (MapObjectInspector) arguments[0]; ObjectInspector mapValueOI = mapOI.getMapValueObjectInspector(); return ObjectInspectorFactory.getStandardListObjectInspector(mapValueOI); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException("The function MAP_KEYS only accepts one argument."); } else if (!(arguments[0] instanceof MapObjectInspector)) { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" is expected at function MAP_KEYS, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } mapOI = (MapObjectInspector) arguments[0]; ObjectInspector mapKeyOI = mapOI.getMapKeyObjectInspector(); return ObjectInspectorFactory.getStandardListObjectInspector(mapKeyOI); }