Refine search
public static boolean isSupportedField(ObjectInspector foi) { if (foi.getCategory() != Category.PRIMITIVE) return false; // not supported PrimitiveCategory pc = ((PrimitiveObjectInspector)foi).getPrimitiveCategory(); if (!SUPPORTED_PRIMITIVES.contains(pc)) return false; // not supported return true; }
protected boolean isStringOrVoidType(ObjectInspector oi) { if (oi.getCategory() == Category.PRIMITIVE) { if (PrimitiveGrouping.STRING_GROUP == PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector) oi).getPrimitiveCategory()) || ((PrimitiveObjectInspector) oi).getPrimitiveCategory() == PrimitiveCategory.VOID) { return true; } } return false; }
public static boolean isSupportedField(ObjectInspector foi) { if (foi.getCategory() != Category.PRIMITIVE) return false; // not supported PrimitiveCategory pc = ((PrimitiveObjectInspector)foi).getPrimitiveCategory(); if (!SUPPORTED_PRIMITIVES.contains(pc)) return false; // not supported return true; }
protected boolean isStringOrVoidType(ObjectInspector oi) { if (oi.getCategory() == Category.PRIMITIVE) { if (PrimitiveGrouping.STRING_GROUP == PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector) oi).getPrimitiveCategory()) || ((PrimitiveObjectInspector) oi).getPrimitiveCategory() == PrimitiveCategory.VOID) { return true; } } return false; }
public static MinorType getDrillType(ObjectInspector oi) { switch(oi.getCategory()) { case PRIMITIVE: { PrimitiveObjectInspector poi = (PrimitiveObjectInspector)oi; if (TYPE_HIVE2DRILL.containsKey(poi.getPrimitiveCategory())) { return TYPE_HIVE2DRILL.get(poi.getPrimitiveCategory()); } throw new UnsupportedOperationException(); } case MAP: case LIST: case STRUCT: default: throw new UnsupportedOperationException(); } }
public static Class<?> getJavaPrimitiveClassFromObjectInspector(ObjectInspector oi) { if (oi.getCategory() != Category.PRIMITIVE) { return null; } PrimitiveObjectInspector poi = (PrimitiveObjectInspector) oi; PrimitiveTypeEntry t = getTypeEntryFromPrimitiveCategory(poi.getPrimitiveCategory()); return t == null ? null : t.primitiveJavaClass; }
void setupParameterOIs(ObjectInspector[] arguments, int start) throws UDFArgumentTypeException { int length = arguments.length - start; parameterOIs = new PrimitiveObjectInspector[length]; parameterTypes = new PrimitiveTypeEntry[length]; parameterClasses = new Class[length]; parameterJavaValues = new Object[length]; for (int i = 0; i < length; i++) { if (arguments[i + start].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The parameters of GenericUDFReflect(class,method[,arg1[,arg2]...])" + " must be primitive (int, double, string, etc)."); } parameterOIs[i] = (PrimitiveObjectInspector)arguments[i + start]; parameterTypes[i] = PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveCategory( parameterOIs[i].getPrimitiveCategory()); parameterClasses[i] = parameterTypes[i].primitiveJavaType == null ? parameterTypes[i].primitiveJavaClass : parameterTypes[i].primitiveJavaType; } }
/** * Convert a Object to a standard Java object in compliance with JDBC 3.0 (see JDBC 3.0 * Specification, Table B-3: Mapping from JDBC Types to Java Object Types). * * This method is kept consistent with HiveResultSetMetaData#hiveTypeToSqlType . */ public static Object toThriftPayload(Object val, ObjectInspector valOI, int version) { if (valOI.getCategory() == ObjectInspector.Category.PRIMITIVE) { if (val == null) { return null; } Object obj = ObjectInspectorUtils.copyToStandardObject(val, valOI, ObjectInspectorUtils.ObjectInspectorCopyOption.JAVA); // uses string type for binary before HIVE_CLI_SERVICE_PROTOCOL_V6 if (version < 5 && ((PrimitiveObjectInspector)valOI).getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.BINARY) { // todo HIVE-5269 return new String((byte[])obj); } return obj; } // for now, expose non-primitive as a string // TODO: expose non-primitive as a structured object while maintaining JDBC compliance return SerDeUtils.getJSONString(val, valOI); }
private void validateAndSetupPatternStr(MatchPath evaluator, List<PTFExpressionDef> args) throws SemanticException { PTFExpressionDef symboPatternArg = args.get(0); ObjectInspector symbolPatternArgOI = symboPatternArg.getOI(); if ( !ObjectInspectorUtils.isConstantObjectInspector(symbolPatternArgOI) || (symbolPatternArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) || ((PrimitiveObjectInspector)symbolPatternArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING ) { throwErrorWithSignature("Currently the symbol Pattern must be a Constant String."); } evaluator.patternStr = ((ConstantObjectInspector)symbolPatternArgOI). getWritableConstantValue().toString(); }
void setupParameterOIs(ObjectInspector[] arguments, int start) throws UDFArgumentTypeException { int length = arguments.length - start; parameterOIs = new PrimitiveObjectInspector[length]; parameterTypes = new PrimitiveTypeEntry[length]; parameterClasses = new Class[length]; parameterJavaValues = new Object[length]; for (int i = 0; i < length; i++) { if (arguments[i + start].getCategory() != ObjectInspector.Category.PRIMITIVE) { throw new UDFArgumentTypeException(i, "The parameters of GenericUDFReflect(class,method[,arg1[,arg2]...])" + " must be primitive (int, double, string, etc)."); } parameterOIs[i] = (PrimitiveObjectInspector)arguments[i + start]; parameterTypes[i] = PrimitiveObjectInspectorUtils.getTypeEntryFromPrimitiveCategory( parameterOIs[i].getPrimitiveCategory()); parameterClasses[i] = parameterTypes[i].primitiveJavaType == null ? parameterTypes[i].primitiveJavaClass : parameterTypes[i].primitiveJavaType; } }
private void validateAndSetupResultExprStr(MatchPath evaluator, List<PTFExpressionDef> args, int argsNum) throws SemanticException { PTFExpressionDef resultExprArg = args.get(argsNum - 1); ObjectInspector resultExprArgOI = resultExprArg.getOI(); if ( !ObjectInspectorUtils.isConstantObjectInspector(resultExprArgOI) || (resultExprArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) || ((PrimitiveObjectInspector)resultExprArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING ) { throwErrorWithSignature("Currently the result Expr parameter must be a Constant String."); } evaluator.resultExprStr = ((ConstantObjectInspector)resultExprArgOI). getWritableConstantValue().toString(); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 2) { throw new UDFArgumentLengthException("Encode() requires exactly two arguments"); } if (arguments[0].getCategory() != Category.PRIMITIVE || PrimitiveGrouping.STRING_GROUP != PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector)arguments[0]).getPrimitiveCategory())){ throw new UDFArgumentTypeException( 0, "The first argument to Encode() must be a string/varchar"); } stringOI = (PrimitiveObjectInspector) arguments[0]; if (arguments[1].getCategory() != Category.PRIMITIVE || PrimitiveGrouping.STRING_GROUP != PrimitiveObjectInspectorUtils.getPrimitiveGrouping( ((PrimitiveObjectInspector)arguments[1]).getPrimitiveCategory())){ throw new UDFArgumentTypeException( 1, "The second argument to Encode() must be a string/varchar"); } charsetOI = (PrimitiveObjectInspector) arguments[1]; // If the character set for encoding is constant, we can optimize that if (charsetOI instanceof ConstantObjectInspector){ String charSetName = ((ConstantObjectInspector) arguments[1]).getWritableConstantValue().toString(); encoder = Charset.forName(charSetName).newEncoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT); } result = new BytesWritable(); return (ObjectInspector) PrimitiveObjectInspectorFactory.writableBinaryObjectInspector; }
private void validateAndSetupPatternStr(MatchPath evaluator, List<PTFExpressionDef> args) throws SemanticException { PTFExpressionDef symboPatternArg = args.get(0); ObjectInspector symbolPatternArgOI = symboPatternArg.getOI(); if ( !ObjectInspectorUtils.isConstantObjectInspector(symbolPatternArgOI) || (symbolPatternArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) || ((PrimitiveObjectInspector)symbolPatternArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING ) { throwErrorWithSignature("Currently the symbol Pattern must be a Constant String."); } evaluator.patternStr = ((ConstantObjectInspector)symbolPatternArgOI). getWritableConstantValue().toString(); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentLengthException( "grouping() requires at least 2 argument, got " + arguments.length); } if (arguments[0].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(0, "The first argument to grouping() must be primitive"); } PrimitiveObjectInspector arg1OI = (PrimitiveObjectInspector) arguments[0]; // INT can happen in cases where grouping() is used without grouping sets, in all other cases it should be LONG. if (!(arg1OI.getPrimitiveCategory() == PrimitiveCategory.INT || arg1OI.getPrimitiveCategory() == PrimitiveCategory.LONG)) { throw new UDFArgumentTypeException(0, "The first argument to grouping() must be an int/long. Got: " + arg1OI.getPrimitiveCategory()); } groupingIdOI = arg1OI; indices = new int[arguments.length - 1]; for (int i = 1; i < arguments.length; i++) { PrimitiveObjectInspector arg2OI = (PrimitiveObjectInspector) arguments[i]; if (!(arg2OI instanceof ConstantObjectInspector)) { throw new UDFArgumentTypeException(i, "Must be a constant. Got: " + arg2OI.getClass().getSimpleName()); } indices[i - 1] = PrimitiveObjectInspectorUtils .getInt(((ConstantObjectInspector) arguments[i]).getWritableConstantValue(), arg2OI); } return PrimitiveObjectInspectorFactory.writableLongObjectInspector; }
private void validateAndSetupResultExprStr(MatchPath evaluator, List<PTFExpressionDef> args, int argsNum) throws SemanticException { PTFExpressionDef resultExprArg = args.get(argsNum - 1); ObjectInspector resultExprArgOI = resultExprArg.getOI(); if ( !ObjectInspectorUtils.isConstantObjectInspector(resultExprArgOI) || (resultExprArgOI.getCategory() != ObjectInspector.Category.PRIMITIVE) || ((PrimitiveObjectInspector)resultExprArgOI).getPrimitiveCategory() != PrimitiveObjectInspector.PrimitiveCategory.STRING ) { throwErrorWithSignature("Currently the result Expr parameter must be a Constant String."); } evaluator.resultExprStr = ((ConstantObjectInspector)resultExprArgOI). getWritableConstantValue().toString(); }
@Override protected int getLength(ObjectInspector objectInspector, ByteArrayRef cachedByteArrayRef, int start, int length) { if (length == 0) { return -1; } Category category = objectInspector.getCategory(); if (category.equals(Category.PRIMITIVE)) { PrimitiveCategory primitiveCategory = ((PrimitiveObjectInspector) objectInspector) .getPrimitiveCategory(); if (primitiveCategory.equals(PrimitiveCategory.STRING) && (length == 1) && (cachedByteArrayRef.getData()[start] == LazyBinaryColumnarSerDe.INVALID_UTF__SINGLE_BYTE[0])) { return 0; } } return length; }
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; } }
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 (arguments[0].getCategory() != Category.PRIMITIVE){ throw new UDFArgumentTypeException(0, "The first argument to Decode() must be primitive"); PrimitiveCategory category = ((PrimitiveObjectInspector)arguments[0]).getPrimitiveCategory(); if (arguments[1].getCategory() != Category.PRIMITIVE) { throw new UDFArgumentTypeException(1, "The second argument to Decode() must be primitive"); .getPrimitiveGrouping(charsetOI.getPrimitiveCategory())) { throw new UDFArgumentTypeException(1, "The second argument to Decode() must be from string group");
if (arguments[0].getCategory() == ObjectInspector.Category.PRIMITIVE) { PrimitiveObjectInspector poi = ((PrimitiveObjectInspector) arguments[0]); if (poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.STRING || poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.CHAR || poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.VARCHAR || poi.getPrimitiveCategory() == PrimitiveObjectInspector.PrimitiveCategory.VOID) { converterFormat = ObjectInspectorConverters.getConverter(arguments[0], resultOI); } else { if (!arguments[i].getCategory().equals(Category.PRIMITIVE)){ throw new UDFArgumentTypeException(i, "Argument " + (i + 1) + " of function PRINTF must be \"" + Category.PRIMITIVE