default: throw new RuntimeException("Hive internal error inside isAssignableFromSettablePrimitiveOI " + oi.getTypeName() + " not supported yet.");
public static HiveIntervalYearMonth getHiveIntervalYearMonth(Object o, PrimitiveObjectInspector oi) { if (o == null) { return null; } HiveIntervalYearMonth result = null; switch (oi.getPrimitiveCategory()) { case VOID: result = null; break; case STRING: case CHAR: case VARCHAR: { try { String val = getString(o, oi).trim(); result = HiveIntervalYearMonth.valueOf(val); } catch (IllegalArgumentException e) { result = null; } break; } case INTERVAL_YEAR_MONTH: result = ((HiveIntervalYearMonthObjectInspector) oi).getPrimitiveJavaObject(o); break; default: throw new RuntimeException("Cannot convert to IntervalYearMonth from: " + oi.getTypeName()); } return result; }
public static HiveIntervalDayTime getHiveIntervalDayTime(Object o, PrimitiveObjectInspector oi) { if (o == null) { return null; } HiveIntervalDayTime result = null; switch (oi.getPrimitiveCategory()) { case VOID: result = null; break; case STRING: case CHAR: case VARCHAR: { try { String val = getString(o, oi).trim(); result = HiveIntervalDayTime.valueOf(val); } catch (IllegalArgumentException e) { result = null; } break; } case INTERVAL_DAY_TIME: result = ((HiveIntervalDayTimeObjectInspector) oi).getPrimitiveJavaObject(o); break; default: throw new RuntimeException("Cannot convert to IntervalDayTime from: " + oi.getTypeName()); } return result; }
/** * Helper function to help GenericUDFs determine the return type * character length for char/varchar. * @param poi PrimitiveObjectInspector representing the type * @return character length of the type * @throws UDFArgumentException */ public static int getFixedStringSizeForType(PrimitiveObjectInspector poi) throws UDFArgumentException { // TODO: we can support date, int, .. any types which would have a fixed length value switch (poi.getPrimitiveCategory()) { case CHAR: case VARCHAR: BaseCharTypeInfo typeInfo = (BaseCharTypeInfo) poi.getTypeInfo(); return typeInfo.getLength(); default: throw new UDFArgumentException("No fixed size for type " + poi.getTypeName()); } }
/** * Helper function to help GenericUDFs determine the return type * character length for char/varchar. * @param poi PrimitiveObjectInspector representing the type * @return character length of the type * @throws UDFArgumentException */ public static int getFixedStringSizeForType(PrimitiveObjectInspector poi) throws UDFArgumentException { // TODO: we can support date, int, .. any types which would have a fixed length value switch (poi.getPrimitiveCategory()) { case CHAR: case VARCHAR: BaseCharTypeInfo typeInfo = (BaseCharTypeInfo) poi.getTypeInfo(); return typeInfo.getLength(); default: throw new UDFArgumentException("No fixed size for type " + poi.getTypeName()); } }
+ " argument of " + opName + " is expected to a " + "numeric type, but " + baseOI.getTypeName() + " is found"); + " argument of " + opName + " is expected to a " + "numeric type, but " + powerOI.getTypeName() + " is found");
"CHARACTER_LENGTH only takes primitive types, got " + argumentOI.getTypeName());
"OCTET_LENGTH only takes primitive types, got " + argumentOI.getTypeName());
public static BytesWritable getBinary(Object o, PrimitiveObjectInspector oi) { if (null == o) { return null; } switch (oi.getPrimitiveCategory()) { case VOID: return null; case STRING: Text text = ((StringObjectInspector) oi).getPrimitiveWritableObject(o); return getBinaryFromText(text); case CHAR: // char to binary conversion: include trailing spaces? return getBinaryFromText( ((HiveCharObjectInspector) oi).getPrimitiveWritableObject(o).getPaddedValue()); case VARCHAR: return getBinaryFromText( ((HiveVarcharObjectInspector) oi).getPrimitiveWritableObject(o).getTextValue()); case BINARY: return ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o); default: throw new RuntimeException("Cannot convert to Binary from: " + oi.getTypeName()); } }
"CHARACTER_LENGTH only takes primitive types, got " + argumentOI.getTypeName());
+ " argument of " + opName + " is expected to a " + "numeric type, but " + baseOI.getTypeName() + " is found"); + " argument of " + opName + " is expected to a " + "numeric type, but " + powerOI.getTypeName() + " is found");
"OCTET_LENGTH only takes primitive types, got " + argumentOI.getTypeName());
" from: " + oi.getTypeName());
"LENGTH only takes primitive types, got " + argumentOI.getTypeName());
"LENGTH only takes primitive types, got " + argumentOI.getTypeName());
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentException(opName + " requires one argument."); } Category category = arguments[0].getCategory(); if (category != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found"); } inputOI = (PrimitiveObjectInspector) arguments[0]; if (!FunctionRegistry.isNumericType(inputOI.getTypeInfo()) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalDayTimeTypeInfo) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalYearMonthTypeInfo)) { throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to be a " + "numeric or interval type, but " + inputOI.getTypeName() + " is found"); } PrimitiveTypeInfo resultTypeInfo = deriveResultTypeInfo(inputOI.getTypeInfo()); resultOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(resultTypeInfo); converter = ObjectInspectorConverters.getConverter(inputOI, resultOI); return resultOI; }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentException(opName + " requires one argument."); } Category category = arguments[0].getCategory(); if (category != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to a " + Category.PRIMITIVE.toString().toLowerCase() + " type, but " + category.toString().toLowerCase() + " is found"); } inputOI = (PrimitiveObjectInspector) arguments[0]; if (!FunctionRegistry.isNumericType(inputOI.getTypeInfo()) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalDayTimeTypeInfo) && (inputOI.getTypeInfo() != TypeInfoFactory.intervalYearMonthTypeInfo)) { throw new UDFArgumentTypeException(0, "The " + GenericUDFUtils.getOrdinal(1) + " argument of " + opName + " is expected to be a " + "numeric or interval type, but " + inputOI.getTypeName() + " is found"); } PrimitiveTypeInfo resultTypeInfo = deriveResultTypeInfo(inputOI.getTypeInfo()); resultOI = PrimitiveObjectInspectorFactory.getPrimitiveWritableObjectInspector(resultTypeInfo); converter = ObjectInspectorConverters.getConverter(inputOI, resultOI); return resultOI; }
default: throw new RuntimeException("Hive 2 Internal error: unsupported conversion from type: " + oi.getTypeName());
+ " argument of " + opName + " is expected to a " + "numeric type, but " + inputOI.getTypeName() + " is found");
+ " argument of " + opName + " is expected to a " + "numeric type, but " + inputOI.getTypeName() + " is found");