@Override public WindowSpecification clone() { WindowSpecification clone = new WindowSpecification(); if (this.partition != null) { clone.setPartition(LanguageObject.Util.deepClone(this.partition, Expression.class)); } if (this.orderBy != null) { clone.setOrderBy(this.orderBy.clone()); } if (this.windowFrame != null) { clone.setWindowFrame(this.windowFrame.clone()); } return clone; }
private void addPartitionCount(int i, WindowFunction wf) { WindowFunction wf2 = new WindowFunction(); wf2.setFunction(new AggregateSymbol(AggregateSymbol.Type.COUNT.name(), false, null)); //clone the partitioning if any WindowSpecification clone = wf.getWindowSpecification().clone(); clone.setOrderBy(null); wf2.setWindowSpecification(clone); WindowSpecificationInfo wsi2 = getOrCreateWindowSpecInfo(clone); WindowFunctionInfo wfi2 = createWindowFunctionInfo(wf2); wfi2.outputIndex = i; wfi2.primaryFunction = wf; wsi2.functions.add(wfi2); }
@Override public void visit(WindowSpecification obj) { preVisitVisitor(obj); visitNodes(obj.getPartition()); visitNode(obj.getOrderBy()); visitNode(obj.getWindowFrame()); postVisitVisitor(obj); }
@Override public WindowSpecification clone() { WindowSpecification clone = new WindowSpecification(); if (this.partition != null) { clone.setPartition(LanguageObject.Util.deepClone(this.partition, Expression.class)); } if (this.orderBy != null) { clone.setOrderBy(this.orderBy.clone()); } return 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); }
@Override public void visit(WindowSpecification obj) { preVisitVisitor(obj); visitNodes(obj.getPartition()); visitNode(obj.getOrderBy()); postVisitVisitor(obj); }
if (wf.getFunction().isRowValueFunction()) { Assertion.assertTrue(ws.getWindowFrame() == null); ws = ws.clone(); WindowFrame frame = new WindowFrame(FrameMode.ROWS); frame.setStart(new FrameBound(BoundMode.PRECEDING)); ws.setWindowFrame(frame);
@Override public void visit(WindowSpecification windowSpecification) { if (windowSpecification.getPartition() == null) { return; } List<Expression> partition = windowSpecification.getPartition(); for (int i = 0; i < partition.size(); i++) { partition.set(i, replaceExpression(partition.get(i))); } }
if (expression instanceof WindowFunction) { WindowFunction wf = (WindowFunction)expression; WindowFrame windowFrame = wf.getWindowSpecification().getWindowFrame(); if (windowFrame != null) { if (Integer.valueOf(0).equals(windowFrame.getStart().getBound())) { && windowFrame.getStart().getBound() == null && windowFrame.getStart().getBoundMode() == BoundMode.PRECEDING) { wf.getWindowSpecification().setWindowFrame(null);
@Override public WindowFunction clone() { WindowFunction clone = new WindowFunction(); clone.setFunction((AggregateSymbol) this.function.clone()); clone.setWindowSpecification(this.windowSpecification.clone()); return clone; }
WindowSpecification ws = new WindowSpecification(); result.setFunction((AggregateSymbol)agg); ws.setPartition(partitionList); ws.setOrderBy(orderBy); result.setWindowSpecification(ws); {if (true) return result;}
@Override public void visit(WindowSpecification windowSpecification) { append(Tokens.LPAREN); boolean needsSpace = false; if (windowSpecification.getPartition() != null) { append(PARTITION); append(SPACE); append(BY); append(SPACE); registerNodes(windowSpecification.getPartition(), 0); needsSpace = true; } if (windowSpecification.getOrderBy() != null) { if (needsSpace) { append(SPACE); } append(windowSpecification.getOrderBy()); } append(Tokens.RPAREN); }
if (wf.getFunction().isRowValueFunction()) { Assertion.assertTrue(ws.getWindowFrame() == null); ws = ws.clone(); WindowFrame frame = new WindowFrame(FrameMode.ROWS); frame.setStart(new FrameBound(BoundMode.PRECEDING)); ws.setWindowFrame(frame);
@Override public void visit(WindowSpecification windowSpecification) { if (windowSpecification.getPartition() == null) { return; } List<Expression> partition = windowSpecification.getPartition(); for (int i = 0; i < partition.size(); i++) { partition.set(i, replaceExpression(partition.get(i))); } }
if (expression instanceof WindowFunction) { WindowFunction wf = (WindowFunction)expression; WindowFrame windowFrame = wf.getWindowSpecification().getWindowFrame(); if (windowFrame != null) { if (Integer.valueOf(0).equals(windowFrame.getStart().getBound())) { && windowFrame.getStart().getBound() == null && windowFrame.getStart().getBoundMode() == BoundMode.PRECEDING) { wf.getWindowSpecification().setWindowFrame(null);
@Override public WindowFunction clone() { WindowFunction clone = new WindowFunction(); clone.setFunction((AggregateSymbol) this.function.clone()); clone.setWindowSpecification(this.windowSpecification.clone()); return clone; }
@Override public WindowSpecification clone() { WindowSpecification clone = new WindowSpecification(); if (this.partition != null) { clone.setPartition(LanguageObject.Util.deepClone(this.partition, Expression.class)); } if (this.orderBy != null) { clone.setOrderBy(this.orderBy.clone()); } if (this.windowFrame != null) { clone.setWindowFrame(this.windowFrame.clone()); } return clone; }
@Override public void visit(WindowSpecification obj) { preVisitVisitor(obj); visitNodes(obj.getPartition()); visitNode(obj.getOrderBy()); visitNode(obj.getWindowFrame()); postVisitVisitor(obj); }
@Test public void testWindowFunction() throws Exception { String sql = "select row_number() over (partition by x order by y) from g"; Query query = new Query(); WindowFunction wf = new WindowFunction(); wf.setFunction(new AggregateSymbol("ROW_NUMBER", false, null)); WindowSpecification ws = new WindowSpecification(); ws.setPartition(new ArrayList<Expression>(Arrays.asList(new ElementSymbol("x")))); ws.setOrderBy(new OrderBy(Arrays.asList(new ElementSymbol("y")))); wf.setWindowSpecification(ws); query.setSelect(new Select(Arrays.asList(wf))); query.setFrom(new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("g"))))); helpTest(sql, "SELECT ROW_NUMBER() OVER (PARTITION BY x ORDER BY y) FROM g", query); }
org.teiid.language.WindowFunction translate(WindowFunction windowFunction) { org.teiid.language.WindowFunction result = new org.teiid.language.WindowFunction(); result.setFunction(translate(windowFunction.getFunction())); WindowSpecification ws = new WindowSpecification(); ws.setOrderBy(translate(windowFunction.getWindowSpecification().getOrderBy(), false)); List<Expression> partition = windowFunction.getWindowSpecification().getPartition(); if (partition != null) { ArrayList<org.teiid.language.Expression> partitionList = translateExpressionList(partition); ws.setPartition(partitionList); } result.setWindowSpecification(ws); return result; }