private WindowFunctionInfo createWindowFunctionInfo(WindowFunction wf) { WindowFunctionInfo wfi = new WindowFunctionInfo(); wfi.function = wf; //collect the agg expressions for (Expression e : wf.getFunction().getArgs()) { GroupingNode.getIndex(e, expressionIndexes); } if (wf.getFunction().getOrderBy() != null) { for (OrderByItem item : wf.getFunction().getOrderBy().getOrderByItems()) { GroupingNode.getIndex(item.getSymbol(), expressionIndexes); } } if (wf.getFunction().getCondition() != null) { GroupingNode.getIndex(wf.getFunction().getCondition(), expressionIndexes); } return wfi; }
private WindowFunctionInfo createWindowFunctionInfo(WindowFunction wf) { WindowFunctionInfo wfi = new WindowFunctionInfo(); wfi.function = wf; //collect the agg expressions for (Expression e : wf.getFunction().getArgs()) { GroupingNode.getIndex(e, expressionIndexes); } if (wf.getFunction().getOrderBy() != null) { for (OrderByItem item : wf.getFunction().getOrderBy().getOrderByItems()) { GroupingNode.getIndex(item.getSymbol(), expressionIndexes); } } if (wf.getFunction().getCondition() != null) { GroupingNode.getIndex(wf.getFunction().getCondition(), expressionIndexes); } return wfi; }
/** * @param functions * @param specIndex * @param rowValues * @return */ private List<AggregateFunction> initializeAccumulators(List<WindowFunctionInfo> functions, int specIndex) { List<AggregateFunction> aggs = new ArrayList<AggregateFunction>(functions.size()); if (functions.isEmpty()) { return aggs; } List<ElementSymbol> elements = new ArrayList<ElementSymbol>(functions.size()); ElementSymbol key = new ElementSymbol("key"); //$NON-NLS-1$ key.setType(DataTypeManager.DefaultDataClasses.INTEGER); elements.add(key); for (WindowFunctionInfo wfi : functions) { AggregateFunction aggregateFunction = GroupingNode.initAccumulator(wfi.function.getFunction(), this, expressionIndexes); aggs.add(aggregateFunction); Class<?> outputType = aggregateFunction.getOutputType(wfi.function.getFunction()); ElementSymbol value = new ElementSymbol("val"); //$NON-NLS-1$ value.setType(outputType); elements.add(value); } valueMapping[specIndex] = this.getBufferManager().createSTree(elements, this.getConnectionID(), 1); return aggs; }
/** * @param functions * @param specIndex * @param rowValues * @return */ private List<AggregateFunction> initializeAccumulators(List<WindowFunctionInfo> functions, int specIndex) { List<AggregateFunction> aggs = new ArrayList<AggregateFunction>(functions.size()); if (functions.isEmpty()) { return aggs; } List<ElementSymbol> elements = new ArrayList<ElementSymbol>(functions.size()); ElementSymbol key = new ElementSymbol("key"); //$NON-NLS-1$ key.setType(DataTypeManager.DefaultDataClasses.INTEGER); elements.add(key); for (WindowFunctionInfo wfi : functions) { AggregateFunction aggregateFunction = GroupingNode.initAccumulator(wfi.function.getFunction(), this, expressionIndexes); aggs.add(aggregateFunction); Class<?> outputType = aggregateFunction.getOutputType(wfi.function.getFunction()); ElementSymbol value = new ElementSymbol("val"); //$NON-NLS-1$ value.setType(outputType); elements.add(value); } valueMapping[specIndex] = this.getBufferManager().createSTree(elements, this.getConnectionID(), 1); return aggs; }
elements.add(key); for (WindowFunctionInfo wfi : functions) { aggs.add(GroupingNode.initAccumulator(wfi.function.getFunction(), this, expressionIndexes)); Class<?> outputType = wfi.function.getType(); if (wfi.function.getFunction().getAggregateFunction() == Type.LEAD || wfi.function.getFunction().getAggregateFunction() == Type.LAG) { outputType = DataTypeManager.getArrayType(DataTypeManager.DefaultDataClasses.OBJECT);
private Map<Integer, Object> createColumnMetadata(String label, Expression symbol) throws QueryMetadataException, TeiidComponentException { if(symbol instanceof ElementSymbol) { return createElementMetadata(label, (ElementSymbol) symbol); } symbol = SymbolMap.getExpression(symbol); if (symbol instanceof AggregateSymbol) { return createAggregateMetadata(label, (AggregateSymbol)symbol); } else if (symbol instanceof WindowFunction) { return createAggregateMetadata(label, ((WindowFunction)symbol).getFunction()); } return createTypedMetadata(label, symbol); }
@Override public void visit(WindowFunction obj) { preVisitVisitor(obj); visitNode(obj.getFunction()); visitNode(obj.getWindowSpecification()); postVisitVisitor(obj); }
@Override public void visit(WindowFunction obj) { preVisitVisitor(obj); visitNode(obj.getFunction()); visitNode(obj.getWindowSpecification()); postVisitVisitor(obj); }
@Override public void visit(WindowFunction obj) { preVisitVisitor(obj); visitNode(obj.getFunction()); visitNode(obj.getWindowSpecification()); postVisitVisitor(obj); }
private Map<Integer, Object> createColumnMetadata(String label, Expression symbol) throws QueryMetadataException, TeiidComponentException { if(symbol instanceof ElementSymbol) { return createElementMetadata(label, (ElementSymbol) symbol); } symbol = SymbolMap.getExpression(symbol); if (symbol instanceof AggregateSymbol) { return createAggregateMetadata(label, (AggregateSymbol)symbol); } else if (symbol instanceof WindowFunction) { return createAggregateMetadata(label, ((WindowFunction)symbol).getFunction()); } return createTypedMetadata(label, symbol); }
private Map<Integer, Object> createColumnMetadata(String label, Expression symbol) throws QueryMetadataException, TeiidComponentException { if(symbol instanceof ElementSymbol) { return createElementMetadata(label, (ElementSymbol) symbol); } symbol = SymbolMap.getExpression(symbol); if (symbol instanceof AggregateSymbol) { return createAggregateMetadata(label, (AggregateSymbol)symbol); } else if (symbol instanceof WindowFunction) { return createAggregateMetadata(label, ((WindowFunction)symbol).getFunction()); } return createTypedMetadata(label, symbol); }
WindowFunction wf = (WindowFunction)ex; WindowSpecification ws = wf.getWindowSpecification(); if (wf.getFunction().isRowValueFunction()) { wfi.outputIndex = i; wsi.functions.add(wfi); if (wf.getFunction().getAggregateFunction() == AggregateSymbol.Type.PERCENT_RANK || wf.getFunction().getAggregateFunction() == AggregateSymbol.Type.CUME_DIST || wf.getFunction().getAggregateFunction() == AggregateSymbol.Type.NTILE) { addPartitionCount(i, wf);
@Override public void visit(WindowFunction windowFunction) { append(windowFunction.getFunction()); append(SPACE); append(OVER); append(SPACE); append(windowFunction.getWindowSpecification()); }
@Override public void visit(WindowFunction windowFunction) { append(windowFunction.getFunction()); append(SPACE); append(OVER); append(SPACE); append(windowFunction.getWindowSpecification()); }
@Override public void visit(WindowFunction windowFunction) { append(windowFunction.getFunction()); append(SPACE); append(OVER); append(SPACE); append(windowFunction.getWindowSpecification()); }
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; }
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)); } }
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); } WindowFrame frame = windowFunction.getWindowSpecification().getWindowFrame(); if (frame != null) { org.teiid.language.WindowFrame resultFrame = new org.teiid.language.WindowFrame(frame.getMode()); resultFrame.setStart(translate(frame.getStart())); resultFrame.setEnd(translate(frame.getEnd())); ws.setWindowFrame(resultFrame); } result.setWindowSpecification(ws); return result; }
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); } WindowFrame frame = windowFunction.getWindowSpecification().getWindowFrame(); if (frame != null) { org.teiid.language.WindowFrame resultFrame = new org.teiid.language.WindowFrame(frame.getMode()); resultFrame.setStart(translate(frame.getStart())); resultFrame.setEnd(translate(frame.getEnd())); ws.setWindowFrame(resultFrame); } result.setWindowSpecification(ws); return result; }