private Converter checkTextArguments(ObjectInspector[] arguments, int i) throws UDFArgumentException { if (arguments[i].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "Only primitive type arguments are accepted but " + arguments[i].getTypeName() + " is passed."); } Converter converter = ObjectInspectorConverters.getConverter((PrimitiveObjectInspector) arguments[i], PrimitiveObjectInspectorFactory.writableStringObjectInspector); return converter; }
public LazyHCatRecord(Object wrappedObject, ObjectInspector oi) throws Exception { if (oi.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only make a lazy hcat record from " + "objects of struct types, but we got: " + oi.getTypeName()); } this.soi = (StructObjectInspector)oi; this.wrappedObject = wrappedObject; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (!arguments[0].getTypeName().equals("boolean")) { throw new UDFArgumentTypeException(0, "First argument for BETWEEN should be boolean type"); } egt.initialize(new ObjectInspector[] {arguments[1], arguments[2]}); elt.initialize(new ObjectInspector[] {arguments[1], arguments[3]}); argumentOIs = arguments; return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
private Converter checkTextArguments(ObjectInspector[] arguments, int i) throws UDFArgumentException { if (arguments[i].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "Only primitive type arguments are accepted but " + arguments[i].getTypeName() + " is passed."); } Converter converter = ObjectInspectorConverters.getConverter((PrimitiveObjectInspector) arguments[i], PrimitiveObjectInspectorFactory.writableStringObjectInspector); return converter; }
private static boolean isInstanceOfSettableOI(ObjectInspector oi) { switch (oi.getCategory()) { case PRIMITIVE: return isInstanceOfSettablePrimitiveOI((PrimitiveObjectInspector)oi); case STRUCT: return oi instanceof SettableStructObjectInspector; case LIST: return oi instanceof SettableListObjectInspector; case MAP: return oi instanceof SettableMapObjectInspector; case UNION: return oi instanceof SettableUnionObjectInspector; default: throw new RuntimeException("Hive internal error inside isAssignableFromSettableOI : " + oi.getTypeName() + " not supported yet."); } }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (!arguments[0].getTypeName().equals("boolean")) { throw new UDFArgumentTypeException(0, "First argument for BETWEEN should be boolean type"); } egt.initialize(new ObjectInspector[] {arguments[1], arguments[2]}); elt.initialize(new ObjectInspector[] {arguments[1], arguments[3]}); argumentOIs = arguments; return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector; }
if (arguments[i].getCategory() == ObjectInspector.Category.PRIMITIVE) { PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) arguments[i]); throw new UDFArgumentTypeException(i, "The argument of function should be \"" + serdeConstants.STRING_TYPE_NAME + "\", but \"" + arguments[i].getTypeName() + "\" is found"); if (arguments[i].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The argument of function should be primative" + ", but \"" + arguments[i].getTypeName() + "\" is found");
@Override public StructObjectInspector initialize(ObjectInspector[] ois) throws UDFArgumentException { //There should be one argument that is a array of struct if (ois.length!=1){ throw new UDFArgumentException("UDF tables only one argument"); } if (ois[0].getCategory()!= Category.LIST){ throw new UDFArgumentException("Top level object must be an array but " + "was "+ois[0].getTypeName()); } li = (ListObjectInspector) ois[0]; ObjectInspector sub=li.getListElementObjectInspector(); if (sub.getCategory() != Category.STRUCT){ throw new UDFArgumentException("The sub element must be struct, but was "+sub.getTypeName()); } return (StructObjectInspector) sub; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentTypeException { argumentOIs = arguments; returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true); for (int i = 0; i + 1 < arguments.length; i += 2) { if (!arguments[i].getTypeName().equals(serdeConstants.BOOLEAN_TYPE_NAME)) { throw new UDFArgumentTypeException(i, "\"" + serdeConstants.BOOLEAN_TYPE_NAME + "\" is expected after WHEN, " + "but \"" + arguments[i].getTypeName() + "\" is found"); } if (!returnOIResolver.update(arguments[i + 1])) { throw new UDFArgumentTypeException(i + 1, "The expressions after THEN should have the same type: \"" + returnOIResolver.get().getTypeName() + "\" is expected but \"" + arguments[i + 1].getTypeName() + "\" is found"); } } if (arguments.length % 2 == 1) { int i = arguments.length - 2; if (!returnOIResolver.update(arguments[i + 1])) { throw new UDFArgumentTypeException(i + 1, "The expression after ELSE should have the same type as those after THEN: \"" + returnOIResolver.get().getTypeName() + "\" is expected but \"" + arguments[i + 1].getTypeName() + "\" is found"); } } return returnOIResolver.get(); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "InBloomFilter requires exactly 2 arguments but got " + arguments.length); } // Verify individual arguments if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The 1st argument must be a primitive type but " + arguments[0].getTypeName() + " was passed"); } if (((PrimitiveObjectInspector) arguments[1]).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BINARY) { throw new UDFArgumentTypeException(1, "The 2nd argument must be a binary type but " + arguments[1].getTypeName() + " was passed"); } valObjectInspector = arguments[0]; bloomFilterObjectInspector = arguments[1]; assert bloomFilterObjectInspector instanceof WritableBinaryObjectInspector; initializedBloomFilter = false; return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector; }
@Override public StructObjectInspector initialize(ObjectInspector[] ois) throws UDFArgumentException { //There should be one argument that is a array of struct if (ois.length!=1){ throw new UDFArgumentException("UDF tables only one argument"); } if (ois[0].getCategory()!= Category.LIST){ throw new UDFArgumentException("Top level object must be an array but " + "was "+ois[0].getTypeName()); } li = (ListObjectInspector) ois[0]; ObjectInspector sub=li.getListElementObjectInspector(); if (sub.getCategory() != Category.STRUCT){ throw new UDFArgumentException("The sub element must be struct, but was "+sub.getTypeName()); } return (StructObjectInspector) sub; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentTypeException { argumentOIs = arguments; returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true); for (int i = 0; i < arguments.length; i++) { if (!returnOIResolver.update(arguments[i])) { throw new UDFArgumentTypeException(i, "The expressions after COALESCE should all have the same type: \"" + returnOIResolver.get().getTypeName() + "\" is expected but \"" + arguments[i].getTypeName() + "\" is found"); } } return returnOIResolver.get(); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException( "The function SIZE only accepts 1 argument."); } Category category = arguments[0].getCategory(); String typeName = arguments[0].getTypeName(); if (category != Category.MAP && category != Category.LIST && !typeName.equals(serdeConstants.VOID_TYPE_NAME)) { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" or \"" + Category.LIST.toString().toLowerCase() + "\" is expected at function SIZE, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } returnOI = arguments[0]; return PrimitiveObjectInspectorFactory.writableIntObjectInspector; }
/** * The purpose of the serialize method is to turn an object-representation * with a provided ObjectInspector into a Writable format, which * the underlying layer can then use to write out. * * In this case, it means that Hive will call this method to convert * an object with appropriate objectinspectors that it knows about, * to write out a HCatRecord. */ @Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only serialize struct types, but we got: " + objInspector.getTypeName()); } return new DefaultHCatRecord((List<Object>) serializeStruct(obj, (StructObjectInspector) objInspector)); }
"The function GET_SPLITS accepts 2 arguments."); } else if (!(arguments[0] instanceof StringObjectInspector)) { LOG.error("Got " + arguments[0].getTypeName() + " instead of string."); throw new UDFArgumentTypeException(0, "\"" + "string\" is expected at function GET_SPLITS, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } else if (!(arguments[1] instanceof IntObjectInspector)) { LOG.error("Got " + arguments[1].getTypeName() + " instead of int."); throw new UDFArgumentTypeException(1, "\"" + "int\" is expected at function GET_SPLITS, " + "but \"" + arguments[1].getTypeName() + "\" is found");
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException( "InBloomFilter requires exactly 2 arguments but got " + arguments.length); } // Verify individual arguments if (arguments[0].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The 1st argument must be a primitive type but " + arguments[0].getTypeName() + " was passed"); } if (((PrimitiveObjectInspector) arguments[1]).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.BINARY) { throw new UDFArgumentTypeException(1, "The 2nd argument must be a binary type but " + arguments[1].getTypeName() + " was passed"); } valObjectInspector = arguments[0]; bloomFilterObjectInspector = arguments[1]; assert bloomFilterObjectInspector instanceof WritableBinaryObjectInspector; initializedBloomFilter = false; return PrimitiveObjectInspectorFactory.javaBooleanObjectInspector; }
if (eloi.getCategory() == Category.PRIMITIVE) { List<Object> list = new ArrayList<Object>(l.size()); for (int i = 0; i < l.size(); i++) { } else if (eloi.getCategory() == Category.STRUCT) { List<List<?>> list = new ArrayList<List<?>>(l.size()); for (int i = 0; i < l.size(); i++) { } else if (eloi.getCategory() == Category.LIST) { List<List<?>> list = new ArrayList<List<?>>(l.size()); for (int i = 0; i < l.size(); i++) { throw new SerDeException(HCatRecordSerDe.class.toString() + " does not know what to do with fields of unknown category: " + eloi.getCategory() + " , type: " + eloi.getTypeName());
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentTypeException { argumentOIs = arguments; returnOIResolver = new GenericUDFUtils.ReturnObjectInspectorResolver(true); for (int i = 0; i + 1 < arguments.length; i += 2) { if (!arguments[i].getTypeName().equals(serdeConstants.BOOLEAN_TYPE_NAME)) { throw new UDFArgumentTypeException(i, "\"" + serdeConstants.BOOLEAN_TYPE_NAME + "\" is expected after WHEN, " + "but \"" + arguments[i].getTypeName() + "\" is found"); } if (!returnOIResolver.update(arguments[i + 1])) { throw new UDFArgumentTypeException(i + 1, "The expressions after THEN should have the same type: \"" + returnOIResolver.get().getTypeName() + "\" is expected but \"" + arguments[i + 1].getTypeName() + "\" is found"); } } if (arguments.length % 2 == 1) { int i = arguments.length - 2; if (!returnOIResolver.update(arguments[i + 1])) { throw new UDFArgumentTypeException(i + 1, "The expression after ELSE should have the same type as those after THEN: \"" + returnOIResolver.get().getTypeName() + "\" is expected but \"" + arguments[i + 1].getTypeName() + "\" is found"); } } return returnOIResolver.get(); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException( "The function SIZE only accepts 1 argument."); } Category category = arguments[0].getCategory(); String typeName = arguments[0].getTypeName(); if (category != Category.MAP && category != Category.LIST && !typeName.equals(serdeConstants.VOID_TYPE_NAME)) { throw new UDFArgumentTypeException(0, "\"" + Category.MAP.toString().toLowerCase() + "\" or \"" + Category.LIST.toString().toLowerCase() + "\" is expected at function SIZE, " + "but \"" + arguments[0].getTypeName() + "\" is found"); } returnOI = arguments[0]; return PrimitiveObjectInspectorFactory.writableIntObjectInspector; }
@Override public Writable serialize(Object obj, ObjectInspector objInspector) throws SerDeException { if (objInspector.getCategory() != Category.STRUCT) { throw new SerDeException(getClass().toString() + " can only serialize struct types, but we got: " + objInspector.getTypeName()); } StructObjectInspector soi = (StructObjectInspector) objInspector; List<? extends StructField> fields = soi.getAllStructFieldRefs(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < fields.size(); i++) { if (i > 0) { sb.append(separator); } Object column = soi.getStructFieldData(obj, fields.get(i)); if (fields.get(i).getFieldObjectInspector().getCategory() == Category.PRIMITIVE) { // For primitive object, serialize to plain string sb.append(column == null ? nullString : column.toString()); } else { // For complex object, serialize to JSON format sb.append(SerDeUtils.getJSONString(column, fields.get(i) .getFieldObjectInspector())); } } serializeCache.set(sb.toString()); return serializeCache; }