private void init(Schema inputSchema, GenericUDTF udtf, ConstantObjectInspectInfo constantsInfo) throws IOException { ResourceSchema rs = new ResourceSchema(inputSchema); ResourceFieldSchema wrappedTupleFieldSchema = new ResourceFieldSchema(); wrappedTupleFieldSchema.setType(DataType.TUPLE); wrappedTupleFieldSchema.setSchema(rs); TypeInfo ti = HiveUtils.getTypeInfo(wrappedTupleFieldSchema); inputObjectInspector = (StructObjectInspector)HiveUtils.createObjectInspector(ti); if (constantsInfo!=null) { constantsInfo.injectConstantObjectInspector(inputObjectInspector); } try { outputObjectInspector = udtf.initialize(inputObjectInspector); } catch (Exception e) { throw new IOException(e); } } }
private void init(Schema inputSchema, GenericUDAFResolver udaf, Mode m, ConstantObjectInspectInfo constantsInfo) throws IOException { try { inputTypeInfo = getInputTypeInfo(inputSchema); inputObjectInspector = (StructObjectInspector)HiveUtils.createObjectInspector(inputTypeInfo); if (constantsInfo!=null) { constantsInfo.injectConstantObjectInspector(inputObjectInspector); } inputObjectInspectorAsArray = getInputObjectInspectorAsArray(inputTypeInfo, constantsInfo); evaluator = getEvaluator(inputTypeInfo, udaf, constantsInfo); if (m == Mode.COMPLETE) { outputObjectInspector = evaluator.init(Mode.COMPLETE, inputObjectInspectorAsArray); outputTypeInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(outputObjectInspector); return; } if (m == Mode.PARTIAL1 || m == Mode.PARTIAL2 || m == Mode.FINAL) { intermediateOutputObjectInspector = evaluator.init(Mode.PARTIAL1, inputObjectInspectorAsArray); intermediateOutputTypeInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(intermediateOutputObjectInspector); if (m == Mode.PARTIAL2 || m == Mode.FINAL) { intermediateInputObjectInspector = HiveUtils.createObjectInspector(intermediateOutputTypeInfo); intermediateInputObjectInspectorAsArray = new ObjectInspector[] {intermediateInputObjectInspector}; outputObjectInspector = evaluator.init(Mode.FINAL, intermediateInputObjectInspectorAsArray); outputTypeInfo = TypeInfoUtils.getTypeInfoFromObjectInspector(outputObjectInspector); } } } catch (Exception e) { throw new IOException(e); } } }