@Override public WindowFrame clone() { WindowFrame clone = new WindowFrame(this.mode); if (start != null) { clone.setStart(start.clone()); } if (end != null) { clone.setEnd(end.clone()); } return clone; }
@Override public WindowFrame clone() { WindowFrame clone = new WindowFrame(this.mode); if (start != null) { clone.setStart(start.clone()); } if (end != null) { clone.setEnd(end.clone()); } return clone; }
WindowFrame frame = new WindowFrame(FrameMode.ROWS); frame.setStart(new FrameBound(BoundMode.PRECEDING)); ws.setWindowFrame(frame);
WindowFrame frame = new WindowFrame(FrameMode.ROWS); frame.setStart(new FrameBound(BoundMode.PRECEDING)); ws.setWindowFrame(frame);
boolean processEachFrame() { for (WindowFunctionInfo info : functions) { //because getting the output is destructive, we need //to process these for each frame //TODO: udfs switch (info.function.getFunction().getAggregateFunction()) { case XMLAGG: case STRING_AGG: case JSONARRAY_AGG: case TEXTAGG: case NTH_VALUE: //the logic needs to know the frame start/end if (windowFrame == null) { //use the default frame range unbounded preceding this.windowFrame = new WindowFrame(FrameMode.RANGE); this.windowFrame.setStart(new FrameBound(BoundMode.PRECEDING)); } return true; } } return windowFrame != null && (windowFrame.getStart().getBound() != null || windowFrame.getStart().getBoundMode() == BoundMode.CURRENT_ROW || (windowFrame.getEnd() != null && windowFrame.getEnd().getBound() != null)); } }
boolean processEachFrame() { for (WindowFunctionInfo info : functions) { //because getting the output is destructive, we need //to process these for each frame //TODO: udfs switch (info.function.getFunction().getAggregateFunction()) { case XMLAGG: case STRING_AGG: case JSONARRAY_AGG: case TEXTAGG: case NTH_VALUE: //the logic needs to know the frame start/end if (windowFrame == null) { //use the default frame range unbounded preceding this.windowFrame = new WindowFrame(FrameMode.RANGE); this.windowFrame.setStart(new FrameBound(BoundMode.PRECEDING)); } return true; } } return windowFrame != null && (windowFrame.getStart().getBound() != null || windowFrame.getStart().getBoundMode() == BoundMode.CURRENT_ROW || (windowFrame.getEnd() != null && windowFrame.getEnd().getBound() != null)); } }
throw new ParseException(); WindowFrame result = new WindowFrame(mode); result.setStart(start); result.setEnd(end);
throw new ParseException(); WindowFrame result = new WindowFrame(mode); result.setStart(start); result.setEnd(end);
@Test public void testEquals() { WindowFrame frame = new WindowFrame(FrameMode.RANGE); frame.setStart(new FrameBound(BoundMode.PRECEDING).bound(1)); frame.setEnd(new FrameBound(BoundMode.CURRENT_ROW)); UnitTestUtil.helpTestEquivalence(0, frame, frame); WindowFrame clone = frame.clone(); UnitTestUtil.helpTestEquivalence(0, frame, clone); clone.setEnd(null); UnitTestUtil.helpTestEquivalence(1, frame, clone); }
@Test public void testWindowFunctionWithFrame() throws Exception { String sql = "select sum(x) over (order by y ROWS BETWEEN CURRENT ROW AND 3 FOLLOWING) from g"; Query query = new Query(); WindowFunction wf = new WindowFunction(); wf.setFunction(new AggregateSymbol("SUM", false, new ElementSymbol("x"))); WindowSpecification ws = new WindowSpecification(); ws.setOrderBy(new OrderBy(Arrays.asList(new ElementSymbol("y")))); WindowFrame frame = new WindowFrame(FrameMode.ROWS); frame.setStart(new WindowFrame.FrameBound(org.teiid.language.WindowFrame.BoundMode.CURRENT_ROW)); frame.setEnd(new WindowFrame.FrameBound(org.teiid.language.WindowFrame.BoundMode.FOLLOWING).bound(3)); ws.setWindowFrame(frame); wf.setWindowSpecification(ws); query.setSelect(new Select(Arrays.asList(wf))); query.setFrom(new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("g"))))); helpTest(sql, "SELECT SUM(x) OVER (ORDER BY y ROWS BETWEEN CURRENT ROW AND 3 FOLLOWING) FROM g", query); }