/** * Gets the next row index that the data within the window are available and can be processed * @param wFrameDef * @return */ public int rowToProcess(WindowFrameDef wFrameDef) { int rowToProcess = numRowsReceived - 1 - Math.max(0, wFrameDef.getEnd().getRelativeOffset()); return rowToProcess >= 0 ? rowToProcess : -1; }
/** * Gets the next row index that the data within the window are available and can be processed * @param wFrameDef * @return */ public int rowToProcess(WindowFrameDef wFrameDef) { int rowToProcess = numRowsReceived - 1 - Math.max(0, wFrameDef.getEnd().getRelativeOffset()); return rowToProcess >= 0 ? rowToProcess : -1; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { State s = (State) agg; Object[] r = s.maxChain.isEmpty() ? null : s.maxChain.getFirst(); // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(r == null ? null : r[0]); } s.numRows++; if (r != null) { int fIdx = (Integer) r[1]; if (!wFrameDef.isStartUnbounded() && s.numRows >= fIdx + wFrameDef.getWindowSize() && !s.maxChain.isEmpty()) { s.maxChain.removeFirst(); r = !s.maxChain.isEmpty() ? s.maxChain.getFirst() : null; } } } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(null); } s.numRows++; } return null; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { State s = (State) agg; ValIndexPair r = s.valueChain.size() == 0 ? null : s.valueChain.getFirst(); // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(r == null ? null : r.val); } s.numRows++; if (r != null) { int fIdx = (Integer) r.idx; if (!wFrameDef.isStartUnbounded() && s.numRows >= fIdx + wFrameDef.getWindowSize() && !s.valueChain.isEmpty()) { s.valueChain.removeFirst(); r = !s.valueChain.isEmpty() ? s.valueChain.getFirst() : r; } } } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(null); } s.numRows++; } return null; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { State s = (State) agg; ValIndexPair r = s.valueChain.size() == 0 ? null : s.valueChain.getFirst(); // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(r == null ? null : r.val); } s.numRows++; if (r != null) { int fIdx = (Integer) r.idx; if (!wFrameDef.isStartUnbounded() && s.numRows >= fIdx + wFrameDef.getWindowSize() && !s.valueChain.isEmpty()) { s.valueChain.removeFirst(); r = !s.valueChain.isEmpty() ? s.valueChain.getFirst() : r; } } } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(null); } s.numRows++; } return null; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { SumAvgStreamingState ss = (SumAvgStreamingState) agg; Object o = wrappedEval.terminate(ss.wrappedBuf); // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (ss.hasResultReady()) { ss.results.add(getNextResult(ss)); } ss.numRows++; } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (ss.hasResultReady()) { ss.results.add(null); } ss.numRows++; } return o; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { State s = (State) agg; Object[] r = s.maxChain.isEmpty() ? null : s.maxChain.getFirst(); // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(r == null ? null : r[0]); } s.numRows++; if (r != null) { int fIdx = (Integer) r[1]; if (!wFrameDef.isStartUnbounded() && s.numRows >= fIdx + wFrameDef.getWindowSize() && !s.maxChain.isEmpty()) { s.maxChain.removeFirst(); r = !s.maxChain.isEmpty() ? s.maxChain.getFirst() : null; } } } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(null); } s.numRows++; } return null; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { SumAvgStreamingState ss = (SumAvgStreamingState) agg; Object o = wrappedEval.terminate(ss.wrappedBuf); // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (ss.hasResultReady()) { ss.results.add(getNextResult(ss)); } ss.numRows++; } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (ss.hasResultReady()) { ss.results.add(null); } ss.numRows++; } return o; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { State s = (State) agg; LastValueBuffer lb = (LastValueBuffer) s.wrappedBuf; if (lb.skipNulls && s.lastIdx != -1) { if (!wFrameDef.isStartUnbounded() && s.numRows >= s.lastIdx + wFrameDef.getWindowSize()) { s.lastValue = null; s.lastIdx = -1; } } // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(s.lastValue); } s.numRows++; } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(null); } s.numRows++; } return null; }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { SumAvgStreamingState ss = (SumAvgStreamingState) agg; wrappedEval.iterate(ss.wrappedBuf, parameters); // We need to insert 'null' before processing first row for the case: X preceding and y preceding if (ss.numRows == 0) { for (int i = wFrameDef.getEnd().getRelativeOffset(); i < 0; i++) { ss.results.add(null); } } // Generate the result for the windowing ending at the current row if (ss.hasResultReady()) { ss.results.add(getNextResult(ss)); } if (!wFrameDef.isStartUnbounded() && ss.numRows + 1 >= wFrameDef.getStart().getRelativeOffset()) { ss.intermediateVals.add(getCurrentIntermediateResult(ss)); } ss.numRows++; }
@Override public Object terminate(AggregationBuffer agg) throws HiveException { State s = (State) agg; LastValueBuffer lb = (LastValueBuffer) s.wrappedBuf; if (lb.skipNulls && s.lastIdx != -1) { if (!wFrameDef.isStartUnbounded() && s.numRows >= s.lastIdx + wFrameDef.getWindowSize()) { s.lastValue = null; s.lastIdx = -1; } } // After all the rows are processed, continue to generate results for the rows that results haven't generated. // For the case: X following and Y following, process first Y-X results and then insert X nulls. // For the case X preceding and Y following, process Y results. for (int i = Math.max(0, wFrameDef.getStart().getRelativeOffset()); i < wFrameDef.getEnd().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(s.lastValue); } s.numRows++; } for (int i = 0; i < wFrameDef.getStart().getRelativeOffset(); i++) { if (s.hasResultReady()) { s.results.add(null); } s.numRows++; } return null; }
@Override public void iterate(AggregationBuffer agg, Object[] parameters) throws HiveException { SumAvgStreamingState ss = (SumAvgStreamingState) agg; wrappedEval.iterate(ss.wrappedBuf, parameters); // We need to insert 'null' before processing first row for the case: X preceding and y preceding if (ss.numRows == 0) { for (int i = wFrameDef.getEnd().getRelativeOffset(); i < 0; i++) { ss.results.add(null); } } // Generate the result for the windowing ending at the current row if (ss.hasResultReady()) { ss.results.add(getNextResult(ss)); } if (!wFrameDef.isStartUnbounded() && ss.numRows + 1 >= wFrameDef.getStart().getRelativeOffset()) { ss.intermediateVals.add(getCurrentIntermediateResult(ss)); } ss.numRows++; }
for (int i = wFrameDef.getEnd().getRelativeOffset(); i < 0; i++) { s.results.add(null);
for (int i = wFrameDef.getEnd().getRelativeOffset(); i < 0; i++) { s.results.add(null); if (s.numRows >= wFrameDef.getEnd().getRelativeOffset()) { s.results.add(s.lastValue);
for (int i = wFrameDef.getEnd().getRelativeOffset(); i < 0; i++) { s.results.add(null);
for (int i = wFrameDef.getEnd().getRelativeOffset(); i < 0; i++) { s.results.add(null); if (s.numRows >= wFrameDef.getEnd().getRelativeOffset()) { s.results.add(s.lastValue);
wrappedEval.iterate(fb, parameters); for (int i = wFrameDef.getEnd().getRelativeOffset(); i < 0; i++) { s.results.add(null);
if (wdwFrame.getWindowType() == WindowType.ROWS) { if (!end.isUnbounded() && !start.isUnbounded()) { startPos = Math.min(startPos, wdwFrame.getStart().getRelativeOffset()); endPos = Math.max(endPos, wdwFrame.getEnd().getRelativeOffset()); continue;
if (wdwFrame.getWindowType() == WindowType.ROWS) { if (!end.isUnbounded() && !start.isUnbounded()) { startPos = Math.min(startPos, wdwFrame.getStart().getRelativeOffset()); endPos = Math.max(endPos, wdwFrame.getEnd().getRelativeOffset()); continue;
GenericUDAFEvaluator fnEval = wFn.getWFnEval(); int numRowsRemaining = wFn.getWindowFrame().getEnd().getRelativeOffset(); if (fnEval != null && fnEval instanceof ISupportStreamingModeForWindowing) {