@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()); if ((f != null) && (foi.getCategory().equals(ObjectInspector.Category.PRIMITIVE)) && ((PrimitiveObjectInspector) foi).getPrimitiveCategory().equals( PrimitiveObjectInspector.PrimitiveCategory.STRING) && ((StringObjectInspector) foi).getPrimitiveJavaObject(f).length() == 0) {
if (arguments[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "ROUND input only takes primitive types, got " + arguments[0].getTypeName()); if (arguments[1].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(1, "ROUND second argument only takes primitive types, got " + arguments[1].getTypeName()); switch (scaleOI.getPrimitiveCategory()) { case VOID: break; inputType = inputOI.getPrimitiveCategory(); ObjectInspector outputOI = null; switch (inputType) { case DECIMAL: DecimalTypeInfo inputTypeInfo = (DecimalTypeInfo) inputOI.getTypeInfo(); DecimalTypeInfo typeInfo = getOutputTypeInfo(inputTypeInfo, scale); outputOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(typeInfo); throw new UDFArgumentTypeException(0, "Only numeric or string group data types are allowed for ROUND function. Got " + inputType.name());
private String describeOi(String desc, ObjectInspector keyOi) { for (StructField field : ((StructObjectInspector)keyOi).getAllStructFieldRefs()) { ObjectInspector oi = field.getFieldObjectInspector(); String cat = oi.getCategory().toString(); if (oi.getCategory() == Category.PRIMITIVE) { cat = ((PrimitiveObjectInspector)oi).getPrimitiveCategory().toString(); } desc += field.getFieldName() + ":" + cat + ", "; } return desc; } }
if (oi1.getCategory() != oi2.getCategory()) { return oi1.getCategory().compareTo(oi2.getCategory()); PrimitiveObjectInspector poi1 = ((PrimitiveObjectInspector) oi1); PrimitiveObjectInspector poi2 = ((PrimitiveObjectInspector) oi2); if (poi1.getPrimitiveCategory() != poi2.getPrimitiveCategory()) { return poi1.getPrimitiveCategory().compareTo( poi2.getPrimitiveCategory());
if (!dType.equals(PrimitiveCategory.STRING)) { int dValue = ((IntObjectInspector) argumentOIs[1]).get(arg1); switch (xObjectInspector.getPrimitiveCategory()) { case VOID: case DOUBLE: + " or \"" + serdeConstants.FLOAT_TYPE_NAME + "\"" + " or \"" + serdeConstants.DECIMAL_TYPE_NAME + "\", but \"" + argumentOIs[0].getTypeName() + "\" was found.");
private boolean mapHasStringKey(ObjectInspector mapKeyObjectInspector) { return mapKeyObjectInspector instanceof PrimitiveObjectInspector && ((PrimitiveObjectInspector) mapKeyObjectInspector) .getPrimitiveCategory() .equals(PrimitiveObjectInspector.PrimitiveCategory.STRING); }
if (!PrimitiveObjectInspectorUtils.getPrimitiveGrouping(originTsOI.getPrimitiveCategory()) .equals(PrimitiveObjectInspectorUtils.PrimitiveGrouping.DATE_GROUP)) { throw new UDFArgumentException("Third arg has to be timestamp got " + originTsOI.getTypeInfo().toString()); if (!PrimitiveObjectInspectorUtils.getPrimitiveGrouping(timestampOI.getPrimitiveCategory()) .equals(PrimitiveObjectInspectorUtils.PrimitiveGrouping.DATE_GROUP)) { throw new UDFArgumentException("First arg has to be timestamp got " + timestampOI.getTypeInfo().toString()); if (!intervalOI.getPrimitiveCategory().equals(PrimitiveObjectInspector.PrimitiveCategory.INTERVAL_DAY_TIME)) { throw new UDFArgumentException("Second arg has to be interval got " + intervalOI.getTypeInfo().toString());
&& !inputSacleConst) { Object scaleObj = null; switch (inputScaleOI.getPrimitiveCategory()) { case BYTE: scaleObj = byteConverter.convert(arguments[1].get()); case DECIMAL: HiveDecimalWritable decimalWritable = (HiveDecimalWritable) inputOI.getPrimitiveWritableObject(input); HiveDecimal dec = trunc(decimalWritable.getHiveDecimal(), scale); if (dec == null) { ByteWritable byteWritable = (ByteWritable) inputOI.getPrimitiveWritableObject(input); if (scale >= 0) { return byteWritable; throw new UDFArgumentTypeException(0, "Only numeric or string group data types are allowed for TRUNC function. Got " + inputType1.name());
HiveDecimalWritable decimalWritable = (HiveDecimalWritable) inputOI.getPrimitiveWritableObject(input); ByteWritable byteWritable = (ByteWritable)inputOI.getPrimitiveWritableObject(input); if (!constantScale) { scale = ((Number)scaleOI.getPrimitiveJavaObject(arguments[1].get())).intValue(); throw new UDFArgumentTypeException(0, "Only numeric or string group data types are allowed for ROUND function. Got " + inputType.name());
HiveDecimalWritable decimalWritable = (HiveDecimalWritable) inputOI.getPrimitiveWritableObject(input); ByteWritable byteWritable = (ByteWritable)inputOI.getPrimitiveWritableObject(input); if (scale >= 0) { return byteWritable; ShortWritable shortWritable = (ShortWritable)inputOI.getPrimitiveWritableObject(input); if (scale >= 0) { return shortWritable; throw new UDFArgumentTypeException(0, "Only numeric or string group data types are allowed for ROUND function. Got " + inputType.name());
private void nullBytesReadError(PrimitiveCategory primitiveCategory, int batchIndex) { throw new RuntimeException("null " + primitiveCategory.name() + " entry: batchIndex " + batchIndex); } }
private ColumnVector castTo(LongColumnVector date, PrimitiveCategory type) { switch (type) { case DATE: return date; case TIMESTAMP: return toTimestamp(date); case STRING: case CHAR: case VARCHAR: return toString(date); default: throw new Error("Unsupported input type " + type.name()); } }
private void nullBytesReadError(PrimitiveCategory primitiveCategory, int batchIndex, int projectionColumnNum) { throw new RuntimeException("null " + primitiveCategory.name() + " entry: batchIndex " + batchIndex + " projection column num " + projectionColumnNum); } }
public static HiveFieldConverter create(TypeInfo typeInfo) throws IllegalAccessException, InstantiationException { switch (typeInfo.getCategory()) { case PRIMITIVE: final PrimitiveCategory pCat = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory(); Class<? extends HiveFieldConverter> clazz = primMap.get(pCat); if (clazz != null) { return clazz.newInstance(); } throwUnsupportedHiveDataTypeError(pCat.toString()); break; case LIST: case MAP: case STRUCT: case UNION: default: throwUnsupportedHiveDataTypeError(typeInfo.getCategory().toString()); } return null; }
return (int) ((secondsAndNanos >>> 32) ^ secondsAndNanos); default: throw new UnsupportedOperationException("Computation of Hive bucket hashCode is not supported for Hive primitive category: " + primitiveCategory.toString() + "."); throw new UnsupportedOperationException("Computation of Hive bucket hashCode is not supported for Hive category: " + type.getCategory().toString() + ".");
private void serialize(int pos, long value) throws IOException { serializeWrite.setAppend(output); // UNDONE: Add support for DATE, TIMESTAMP, INTERVAL_YEAR_MONTH, INTERVAL_DAY_TIME... switch (primitiveCategory) { case BOOLEAN: serializeWrite.writeBoolean(value != 0); break; case BYTE: serializeWrite.writeByte((byte) value); break; case SHORT: serializeWrite.writeShort((short) value); break; case INT: serializeWrite.writeInt((int) value); break; case LONG: serializeWrite.writeLong(value); break; default: throw new RuntimeException("Unexpected primitive category " + primitiveCategory.name()); } int outputNewPosition = output.getLength(); serializedKeyLengths[pos] = outputNewPosition - currentKeyStart; currentKeyStart = outputNewPosition; } }
return (int) ((secondsAndNanos >>> 32) ^ secondsAndNanos); default: throw new UnsupportedOperationException("Computation of Hive bucket hashCode is not supported for Hive primitive category: " + primitiveCategory.toString() + "."); throw new UnsupportedOperationException("Computation of Hive bucket hashCode is not supported for Hive category: " + type.getCategory().toString() + ".");
return dateVector; default: throw new Error("Unsupported input type " + primitiveCategory.name());
private void serialize(int pos, long value) throws IOException { serializeWrite.setAppend(output); // UNDONE: Add support for DATE, TIMESTAMP, INTERVAL_YEAR_MONTH, INTERVAL_DAY_TIME... switch (primitiveCategory) { case BOOLEAN: serializeWrite.writeBoolean(value != 0); break; case BYTE: serializeWrite.writeByte((byte) value); break; case SHORT: serializeWrite.writeShort((short) value); break; case INT: serializeWrite.writeInt((int) value); break; case LONG: serializeWrite.writeLong(value); break; default: throw new RuntimeException("Unexpected primitive category " + primitiveCategory.name()); } int outputNewPosition = output.getLength(); serializedKeyLengths[pos] = outputNewPosition - currentKeyStart; currentKeyStart = outputNewPosition; } }