public Object clone(){ WindowFunctionProjectNode clonedNode = new WindowFunctionProjectNode(); this.copyTo(clonedNode); clonedNode.windows = windows; clonedNode.expressionIndexes = expressionIndexes; clonedNode.passThrough = passThrough; return clonedNode; }
@Override public void initialize(CommandContext context, BufferManager bufferManager, ProcessorDataManager dataMgr) { super.initialize(context, bufferManager, dataMgr); if (this.elementMap == null) { List<? extends Expression> sourceElements = this.getChildren()[0].getElements(); this.elementMap = createLookupMap(sourceElements); } }
private void saveValues(int specIndex, List<AggregateFunction> aggs, Object id, boolean samePartition) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { if (aggs.isEmpty()) { return; } List<Object> row = new ArrayList<Object>(aggs.size() + 1); row.add(id); for (AggregateFunction function : aggs) { row.add(function.getResult(getContext())); if (!samePartition) { function.reset(); } } valueMapping[specIndex].insert(row, InsertMode.ORDERED, -1); }
saveInput(); phase = Phase.PROCESS; partitionMapping = new STree[this.windows.size()]; buildResults(); phase = Phase.OUTPUT; List<?> tuple = outputTs.nextTuple(); Integer rowId = (Integer)tuple.get(tuple.size() - 1); int size = getElements().size(); ArrayList<Object> outputRow = new ArrayList<Object>(size); for (int i = 0; i < size; i++) { this.addBatchRow(outputRow); if (this.isBatchFull()) { return pullBatch(); terminateBatches(); return this.pullBatch();
value.setType(DataTypeManager.DefaultDataClasses.INTEGER); List<ElementSymbol> elements = Arrays.asList(key, value); partitionMapping[specIndex] = this.getBufferManager().createSTree(elements, this.getConnectionID(), 1); SortUtility su = new SortUtility(null, Mode.SORT, this.getBufferManager(), this.getConnectionID(), tb.getSchema(), info.orderType, info.nullOrderings, sortKeys); su.setWorkingBuffer(tb); su.setNonBlocking(true); specificationTs = sorted.createIndexedTupleSource(true); List<AggregateFunction> aggs = initializeAccumulators(info.functions, specIndex, false); List<AggregateFunction> rowValueAggs = initializeAccumulators(info.rowValuefunctions, specIndex, true); boolean samePartition = GroupingNode.sameGroup(partitionIndexes, tuple, lastRow) == -1; if (!aggs.isEmpty() && (!samePartition || GroupingNode.sameGroup(orderIndexes, tuple, lastRow) != -1)) { saveValues(specIndex, aggs, groupId, samePartition, false); groupId++; saveValues(specIndex, rowValueAggs, lastRow.get(lastRow.size() - 1), samePartition, true); function.addInput(tuple, getContext()); function.addInput(tuple, getContext()); saveValues(specIndex, aggs, groupId, true, false); saveValues(specIndex, rowValueAggs, lastRow.get(lastRow.size() - 1), true, true);
if (inputTs == null) { List<Expression> collectedExpressions = new ArrayList<Expression>(expressionIndexes.keySet()); Evaluator eval = new Evaluator(elementMap, getDataManager(), getContext()); final RelationalNode sourceNode = this.getChildren()[0]; inputTs = new ProjectingTupleSource(sourceNode, eval, collectedExpressions, elementMap) { int index = 0; es.setType(DataTypeManager.DefaultDataClasses.INTEGER); schema.add(es); tb = this.getBufferManager().createTupleBuffer(schema, this.getConnectionID(), TupleSourceType.PROCESSOR);
WindowFunctionProjectNode wfpn = new WindowFunctionProjectNode(getID()); outputElements.add(singleElementSymbol); wfpn.setElements(outputElements); wfpn.init(); pnode.addChild(wfpn); for (WindowFunction wf : windowFunctions) {
/** * @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; }
for (AggregateFunction function : aggs) { if (function instanceof NthValue) { ((NthValue) function).addInput(frameTuple, getContext(), start, end, sorted); } else { function.addInput(frameTuple, getContext()); saveValues(specIndex, aggs, groupId, false);
saveInput(); phase = Phase.PROCESS; partitionMapping = new STree[this.windows.size()]; buildResults(); phase = Phase.OUTPUT; List<?> tuple = outputTs.nextTuple(); Integer rowId = (Integer)tuple.get(tuple.size() - 1); int size = getElements().size(); ArrayList<Object> outputRow = new ArrayList<Object>(size); for (int i = 0; i < size; i++) { this.addBatchRow(outputRow); if (this.isBatchFull()) { return pullBatch(); terminateBatches(); return this.pullBatch();
value.setType(DataTypeManager.DefaultDataClasses.INTEGER); List<ElementSymbol> elements = Arrays.asList(key, value); partitionMapping[specIndex] = this.getBufferManager().createSTree(elements, this.getConnectionID(), 1); SortUtility su = new SortUtility(null, Mode.SORT, this.getBufferManager(), this.getConnectionID(), tb.getSchema(), info.orderType, info.nullOrderings, sortKeys); su.setWorkingBuffer(tb); su.setNonBlocking(true); List<AggregateFunction> aggs = initializeAccumulators(info.functions, specIndex); processEachFrame(specIndex, info, specificationTs, partitionIndexes, orderIndexes, sorted, aggs); return; && ((info.windowFrame != null && info.windowFrame.getMode() == FrameMode.ROWS) || GroupingNode.sameGroup(orderIndexes, tuple, lastRow) != -1))) { saveValues(specIndex, aggs, groupId, samePartition); groupId++; function.addInput(tuple, getContext()); saveValues(specIndex, aggs, groupId, true);
if (inputTs == null) { List<Expression> collectedExpressions = new ArrayList<Expression>(expressionIndexes.keySet()); Evaluator eval = new Evaluator(elementMap, getDataManager(), getContext()); final RelationalNode sourceNode = this.getChildren()[0]; inputTs = new ProjectingTupleSource(sourceNode, eval, collectedExpressions, elementMap) { int index = 0; es.setType(DataTypeManager.DefaultDataClasses.INTEGER); schema.add(es); tb = this.getBufferManager().createTupleBuffer(schema, this.getConnectionID(), TupleSourceType.PROCESSOR);
WindowFunctionProjectNode wfpn = new WindowFunctionProjectNode(getID()); outputElements.add(singleElementSymbol); wfpn.setElements(outputElements); wfpn.init(); pnode.addChild(wfpn); for (WindowFunction wf : windowFunctions) {
/** * @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; }
for (AggregateFunction function : aggs) { if (function instanceof NthValue) { ((NthValue) function).addInput(frameTuple, getContext(), start, end, sorted); } else { function.addInput(frameTuple, getContext()); saveValues(specIndex, aggs, groupId, false);
saveInput(); phase = Phase.PROCESS; partitionMapping = new STree[this.windows.size()]; buildResults(); phase = Phase.OUTPUT; List<?> tuple = outputTs.nextTuple(); Integer rowId = (Integer)tuple.get(tuple.size() - 1); int size = getElements().size(); ArrayList<Object> outputRow = new ArrayList<Object>(size); for (int i = 0; i < size; i++) { this.addBatchRow(outputRow); if (this.isBatchFull()) { return pullBatch(); terminateBatches(); return this.pullBatch();
value.setType(DataTypeManager.DefaultDataClasses.INTEGER); List<ElementSymbol> elements = Arrays.asList(key, value); partitionMapping[specIndex] = this.getBufferManager().createSTree(elements, this.getConnectionID(), 1); SortUtility su = new SortUtility(null, Mode.SORT, this.getBufferManager(), this.getConnectionID(), tb.getSchema(), info.orderType, info.nullOrderings, sortKeys); su.setWorkingBuffer(tb); su.setNonBlocking(true); List<AggregateFunction> aggs = initializeAccumulators(info.functions, specIndex); processEachFrame(specIndex, info, specificationTs, partitionIndexes, orderIndexes, sorted, aggs); return; && ((info.windowFrame != null && info.windowFrame.getMode() == FrameMode.ROWS) || GroupingNode.sameGroup(orderIndexes, tuple, lastRow) != -1))) { saveValues(specIndex, aggs, groupId, samePartition); groupId++; function.addInput(tuple, getContext()); saveValues(specIndex, aggs, groupId, true);
if (inputTs == null) { List<Expression> collectedExpressions = new ArrayList<Expression>(expressionIndexes.keySet()); Evaluator eval = new Evaluator(elementMap, getDataManager(), getContext()); final RelationalNode sourceNode = this.getChildren()[0]; inputTs = new ProjectingTupleSource(sourceNode, eval, collectedExpressions, elementMap) { int index = 0; es.setType(DataTypeManager.DefaultDataClasses.INTEGER); schema.add(es); tb = this.getBufferManager().createTupleBuffer(schema, this.getConnectionID(), TupleSourceType.PROCESSOR);
WindowFunctionProjectNode wfpn = new WindowFunctionProjectNode(getID()); outputElements.add(singleElementSymbol); wfpn.setElements(outputElements); wfpn.init(); pnode.addChild(wfpn); for (WindowFunction wf : windowFunctions) {
public Object clone(){ WindowFunctionProjectNode clonedNode = new WindowFunctionProjectNode(); this.copyTo(clonedNode); clonedNode.windows = windows; clonedNode.expressionIndexes = expressionIndexes; clonedNode.passThrough = passThrough; return clonedNode; }