static void setupWdwFnEvaluator(WindowFunctionDef def) throws HiveException { ArrayList<PTFExpressionDef> args = def.getArgs(); ArrayList<ObjectInspector> argOIs = new ArrayList<ObjectInspector>(); ObjectInspector[] funcArgOIs = null; if (args != null) { for (PTFExpressionDef arg : args) { argOIs.add(arg.getOI()); } funcArgOIs = new ObjectInspector[args.size()]; funcArgOIs = argOIs.toArray(funcArgOIs); } GenericUDAFEvaluator wFnEval = def.getWFnEval(); ObjectInspector OI = wFnEval.init(GenericUDAFEvaluator.Mode.COMPLETE, funcArgOIs); def.setWFnEval(wFnEval); def.setOI(OI); }
public void initializeWindowing(WindowTableFunctionDef def) throws HiveException { ShapeDetails inpShape = def.getInput().getOutputShape(); /* * 1. setup resolve, make connections */ TableFunctionEvaluator tEval = def.getTFunction(); WindowingTableFunctionResolver tResolver = (WindowingTableFunctionResolver) constructResolver(def.getResolverClassName()); tResolver.initialize(ptfDesc, def, tEval); /* * 2. initialize WFns. */ if (def.getWindowFunctions() != null) { for (WindowFunctionDef wFnDef : def.getWindowFunctions()) { if (wFnDef.getArgs() != null) { for (PTFExpressionDef arg : wFnDef.getArgs()) { initialize(arg, inpShape); } } if (wFnDef.getWindowFrame() != null) { WindowFrameDef wFrmDef = wFnDef.getWindowFrame(); initialize(wFrmDef.getStart(), inpShape); initialize(wFrmDef.getEnd(), inpShape); } setupWdwFnEvaluator(wFnDef); } ArrayList<String> aliases = new ArrayList<String>(); ArrayList<ObjectInspector> fieldOIs = new ArrayList<ObjectInspector>(); for (WindowFunctionDef wFnDef : def.getWindowFunctions()) { aliases.add(wFnDef.getAlias()); if (wFnDef.isPivotResult()) { fieldOIs.add(((ListObjectInspector) wFnDef.getOI()).getListElementObjectInspector()); } else { fieldOIs.add(wFnDef.getOI()); } } PTFDeserializer.addInputColumnsToList(inpShape, aliases, fieldOIs); StructObjectInspector wdwOutOI = ObjectInspectorFactory.getStandardStructObjectInspector(aliases, fieldOIs); tResolver.setWdwProcessingOutputOI(wdwOutOI); initialize(def.getOutputFromWdwFnProcessing(), wdwOutOI); } else { def.setOutputFromWdwFnProcessing(inpShape); } inpShape = def.getOutputFromWdwFnProcessing(); /* * 3. initialize WExprs. + having clause */ if (def.getWindowExpressions() != null) { for (WindowExpressionDef wEDef : def.getWindowExpressions()) { initialize(wEDef, inpShape); } } /* * 4. give Evaluator chance to setup for Output execution; setup Output shape. */ tResolver.initializeOutputOI(); initialize(def.getOutputShape(), tEval.getOutputOI()); /* * If we have windowExpressions then we convert to Std. Object to process; * we just stream these rows; no need to put in an output Partition. */ if (def.getWindowExpressions().size() > 0) { StructObjectInspector oi = (StructObjectInspector) ObjectInspectorUtils.getStandardObjectInspector(def.getOutputShape().getOI()); def.getOutputShape().setOI(oi); } }