@Override protected HiveDecimalObjectInspector getValueObjectInspector(PrimitiveTypeInfo typeInfo) { return (JavaHiveDecimalObjectInspector)PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(typeInfo); }
@Override protected HiveDecimalObjectInspector getValueObjectInspector(PrimitiveTypeInfo typeInfo) { return (JavaHiveDecimalObjectInspector)PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(typeInfo); }
static ArrayList<ObjectInspector> getFieldObjectInspectors(int fields) { ArrayList<ObjectInspector> r = new ArrayList<ObjectInspector>(fields); for (int i = 0; i < fields; i++) { r.add(PrimitiveObjectInspectorFactory .getPrimitiveJavaObjectInspector(PrimitiveCategory.STRING)); } return r; }
@Override protected ObjectInspector getSumFieldJavaObjectInspector() { DecimalTypeInfo typeInfo = deriveResultDecimalTypeInfo(); return PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(typeInfo); }
@Override protected ObjectInspector getSumFieldJavaObjectInspector() { DecimalTypeInfo typeInfo = deriveResultDecimalTypeInfo(); return PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(typeInfo); }
static synchronized public ObjectPair<PrimitiveObjectInspector, ExprNodeEvaluator> prepareExpr( ExprNodeGenericFuncDesc expr, List<String> partColumnNames, List<PrimitiveTypeInfo> partColumnTypeInfos) throws HiveException { // Create the row object List<ObjectInspector> partObjectInspectors = new ArrayList<ObjectInspector>(); for (int i = 0; i < partColumnNames.size(); i++) { partObjectInspectors.add(PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector( partColumnTypeInfos.get(i))); } StructObjectInspector objectInspector = ObjectInspectorFactory .getStandardStructObjectInspector(partColumnNames, partObjectInspectors); ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(expr); ObjectInspector evaluateResultOI = evaluator.initialize(objectInspector); return ObjectPair.create((PrimitiveObjectInspector)evaluateResultOI, evaluator); }
@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); }
static synchronized public ObjectPair<PrimitiveObjectInspector, ExprNodeEvaluator> prepareExpr( ExprNodeGenericFuncDesc expr, List<String> partColumnNames, List<PrimitiveTypeInfo> partColumnTypeInfos) throws HiveException { // Create the row object List<ObjectInspector> partObjectInspectors = new ArrayList<ObjectInspector>(); for (int i = 0; i < partColumnNames.size(); i++) { partObjectInspectors.add(PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector( partColumnTypeInfos.get(i))); } StructObjectInspector objectInspector = ObjectInspectorFactory .getStandardStructObjectInspector(partColumnNames, partObjectInspectors); ExprNodeEvaluator evaluator = ExprNodeEvaluatorFactory.get(expr); ObjectInspector evaluateResultOI = evaluator.initialize(objectInspector); return ObjectPair.create((PrimitiveObjectInspector)evaluateResultOI, evaluator); }
/** * Returns an ObjectInspector for a primitive Class. The Class can be a Hive * Writable class, or a Java Primitive Class. * * A runtimeException will be thrown if the class is not recognized as a * primitive type by Hive. */ public static PrimitiveObjectInspector getPrimitiveObjectInspectorFromClass( Class<?> c) { if (Writable.class.isAssignableFrom(c)) { // It is a writable class PrimitiveTypeEntry te = PrimitiveObjectInspectorUtils .getTypeEntryFromPrimitiveWritableClass(c); if (te == null) { throw new RuntimeException("Internal error: Cannot recognize " + c); } return PrimitiveObjectInspectorFactory .getPrimitiveWritableObjectInspector(te.primitiveCategory); } else { // It is a Java class PrimitiveTypeEntry te = PrimitiveObjectInspectorUtils .getTypeEntryFromPrimitiveJavaClass(c); if (te == null) { throw new RuntimeException("Internal error: Cannot recognize " + c); } return PrimitiveObjectInspectorFactory .getPrimitiveJavaObjectInspector(te.primitiveCategory); } }
@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); }
return getPrimitiveJavaObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
public void prepareConstant() { final Object writableValue; if (constExpr != null) { PrimitiveCategory pc = ((PrimitiveTypeInfo) constExpr.getTypeInfo()) .getPrimitiveCategory(); // Convert from Java to Writable writableValue = PrimitiveObjectInspectorFactory .getPrimitiveJavaObjectInspector(pc).getPrimitiveWritableObject( constExpr.getValue()); } else { writableValue = null; } constObjVal = new GenericUDF.DeferredJavaObject(writableValue); }
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length < 2) { throw new UDFArgumentLengthException( "The function GenericUDFReflect(class,method[,arg1[,arg2]...])" + " accepts 2 or more arguments."); } for (int i = 0; i < 2; i++) { if (!(arguments[i] instanceof StringObjectInspector)) { throw new UDFArgumentTypeException(i, "The first 2 parameters of GenericUDFReflect(class,method[,arg1[,arg2]...])" + " should be string."); } } inputClassNameOI = (StringObjectInspector) arguments[0]; inputMethodNameOI = (StringObjectInspector) arguments[1]; classNameOI = (StringObjectInspector) ObjectInspectorUtils.getStandardObjectInspector(arguments[0]); methodNameOI = (StringObjectInspector) ObjectInspectorUtils.getStandardObjectInspector(arguments[1]); setupParameterOIs(arguments, 2); return PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector( PrimitiveCategory.STRING); }
@Override public InspectableObject[] getBaseTable() { DataBuilder db = new DataBuilder(); db.setColumnNames(cols); db.setColumnTypes( PrimitiveObjectInspectorFactory.javaStringObjectInspector, PrimitiveObjectInspectorFactory.javaIntObjectInspector, PrimitiveObjectInspectorFactory.javaDoubleObjectInspector, PrimitiveObjectInspectorFactory.javaFloatObjectInspector, PrimitiveObjectInspectorFactory.javaByteObjectInspector, PrimitiveObjectInspectorFactory.javaShortObjectInspector, PrimitiveObjectInspectorFactory.javaLongObjectInspector, PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(TypeInfoFactory.getDecimalTypeInfo(15, 5))); db.addRow("one", 170, new Double("1.1"), new Float("32.1234"), new Byte("25"), new Short("1234"), 123456L, HiveDecimal.create("983.7235")); db.addRow( "-234", null, null, new Float("0.347232"), new Byte("109"), new Short("551"), 923L, HiveDecimal.create("983723.005")); db.addRow("454.45", 22345, new Double("-23.00009"), new Float("-3.4"), new Byte("76"), new Short("2321"), 9232L, HiveDecimal.create("-932032.7")); return db.createRows(); }
return getPrimitiveJavaObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
return getPrimitiveJavaObjectInspector(new DecimalTypeInfo(decimalType.getPrecision(), decimalType.getScale()));
PrimitiveTypeEntry pte = PrimitiveObjectInspectorUtils .getTypeEntryFromPrimitiveJavaClass(bt.getRealType()); return PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(pte.primitiveCategory); } else {
@Override public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException { if (arguments.length != 1) { throw new UDFArgumentLengthException(String.format("%s needs 1 argument, got %d", udfName, arguments.length)); } if (arguments[0].getCategory() != Category.PRIMITIVE || ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory() != inputType) { String actual = arguments[0].getCategory() + (arguments[0].getCategory() == Category.PRIMITIVE ? "[" + ((PrimitiveObjectInspector) arguments[0]).getPrimitiveCategory() + "]" : ""); throw new UDFArgumentException( String.format("%s only takes primitive type %s, got %s", udfName, inputType, actual)); } argumentOI = arguments[0]; return PrimitiveObjectInspectorFactory.getPrimitiveJavaObjectInspector(outputType); }
throws Exception TestColumn writeColumn = new TestColumn("varchar_column", getPrimitiveJavaObjectInspector(new VarcharTypeInfo(4)), new HiveVarchar("test", 4), utf8Slice("test")); TestColumn readColumn = new TestColumn("varchar_column", getPrimitiveJavaObjectInspector(new VarcharTypeInfo(3)), new HiveVarchar("tes", 3), utf8Slice("tes"));
throws Exception TestColumn partitionColumn = new TestColumn("partition_column", getPrimitiveJavaObjectInspector(new VarcharTypeInfo(3)), "test", utf8Slice("tes"), true); TestColumn varcharColumn = new TestColumn("varchar_column", getPrimitiveJavaObjectInspector(new VarcharTypeInfo(3)), new HiveVarchar("tes", 3), utf8Slice("tes"));