public Object clone(){ GroupingNode clonedNode = new GroupingNode(super.getID()); super.copyTo(clonedNode); clonedNode.removeDuplicates = removeDuplicates; clonedNode.outputMapping = outputMapping; clonedNode.orderBy = orderBy; clonedNode.rollup = rollup; return clonedNode; }
private TupleBatch groupPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { CommandContext context = getContext(); while(!doneReading) { int colDiff = sameGroup(indexes, currentGroupTuple, lastRow); if (colDiff != -1) { closeGroup(colDiff, true, context); if (this.isBatchFull()) { return pullBatch(); updateAggregates(currentGroupTuple); currentGroupTuple = null; closeGroup(-1, false, context); this.terminateBatches(); return pullBatch();
aggregateFunction.setState(tuple, index); index+=this.accumulatorStateCount[i]; vals.set(size + i, aggregateFunction.getResult(getContext())); addBatchRow(result); if (isBatchFull()) { return pullBatch(); terminateBatches(); return pullBatch();
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException { // Take inputs, evaluate expressions, and build initial tuple source if(this.phase == COLLECTION) { collectionPhase(); } // If necessary, sort to determine groups (if no group cols, no need to sort) if(this.phase == SORT) { sortPhase(); } // Walk through the sorted results and for each group, emit a row if(this.phase == GROUP) { return groupPhase(); } if (this.phase == GROUP_SORT) { groupSortPhase(); } if (this.phase == GROUP_SORT_OUTPUT) { return groupSortOutputPhase(); } this.terminateBatches(); return pullBatch(); }
GroupingNode gnode = new GroupingNode(getID()); gnode.setRollup(node.hasBooleanProperty(Info.ROLLUP)); SymbolMap groupingMap = (SymbolMap)node.getProperty(NodeConstants.Info.SYMBOL_MAP); gnode.setOutputMapping(groupingMap); gnode.setRemoveDuplicates(node.hasBooleanProperty(NodeConstants.Info.IS_DUP_REMOVAL)); List<Expression> gCols = (List) node.getProperty(NodeConstants.Info.GROUP_COLS); OrderBy orderBy = (OrderBy) node.getProperty(Info.SORT_ORDER); gnode.setOrderBy(orderBy.getOrderByItems());
private GroupingNode getExampleGroupingNode() { GroupingNode node = new GroupingNode(1); List outputElements = new ArrayList(); ElementSymbol col1 = new ElementSymbol("col1"); //$NON-NLS-1$ col1.setType(Integer.class); ElementSymbol col2 = new ElementSymbol("col2"); //$NON-NLS-1$ col2.setType(Integer.class); outputElements.add(col1); outputElements.add(new AggregateSymbol("COUNT", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$ node.setElements(outputElements); List groupingElements = new ArrayList(); groupingElements.add(col1); node.setOrderBy(new OrderBy(groupingElements).getOrderByItems()); return node; }
List<? extends Expression> sourceElements = this.getChildren()[0].getElements(); this.elementMap = createLookupMap(sourceElements); this.collectedExpressions = new LinkedHashMap<Expression, Integer>(); for (OrderByItem item : this.orderBy) { Expression ex = SymbolMap.getExpression(item.getSymbol()); getIndex(ex, this.collectedExpressions); getIndex(ses, collectedExpressions); functions = new AggregateFunction[getElements().size()][]; for(int i=0; i<getElements().size(); i++) { Expression symbol = getElements().get(i); if (this.outputMapping != null) { symbol = outputMapping.getMappedExpression((ElementSymbol)symbol); functions[i] = new AggregateFunction[rollup?orderBy.size()+1:1]; for (int j = 0; j < functions[i].length; j++) { functions[i][j] = initAccumulator(aggSymbol, this, this.collectedExpressions);
GroupingNode groupNode = new GroupingNode(accessNode.getID()); AggregateSymbol sumCount = new AggregateSymbol(NonReserved.SUM, false, accessNode.getElements().get(0)); groupNode.setElements(Arrays.asList(sumCount)); groupNode.addChild(unionNode);
GroupingNode node = new GroupingNode(1); List outputElements = new ArrayList(); ElementSymbol col1 = new ElementSymbol("col1"); //$NON-NLS-1$ outputElements.add(new AggregateSymbol("MAX", false, col2)); //$NON-NLS-1$ //$NON-NLS-2$ outputElements.add(new AggregateSymbol("MAX", true, col2)); //$NON-NLS-1$ //$NON-NLS-2$ node.setElements(outputElements); node.setOrderBy(new OrderBy(groupingElements).getOrderByItems()); CommandContext context = new CommandContext("pid", "test", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$ AggregateFunction[][] functions = node.getFunctions(); AggregateFunction countDist = functions[5][0]; SortingFilter dup = (SortingFilter)countDist;
GroupingNode node = new GroupingNode(1); List outputElements = new ArrayList(); outputElements.add(new AggregateSymbol("SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$ outputElements.add(new AggregateSymbol("AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$ node.setElements(outputElements);
RelationalNode dataNode = new FakeRelationalNode(0, dataSource, mgr.getProcessorBatchSize()); dataNode.setElements(dataSource.getSchema()); node.addChild(dataNode); node.initialize(context, mgr, dataMgr); node.open(); TupleBatch batch = node.nextBatch(); for(int row = currentRow; row <= batch.getEndRow(); row++) { List tuple = batch.getTuple(row);
@Test public void testDescriptionProperties() { GroupingNode node = getExampleGroupingNode(); SymbolMap outputMapping = new SymbolMap(); outputMapping.addMapping(new ElementSymbol("agg0"), new AggregateSymbol("count", false, null)); node.setOutputMapping(outputMapping); PlanNode pn = node.getDescriptionProperties(); assertTrue(pn.toString().contains("agg0=count(*)")); }
@Override protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { if (block) { block = false; throw BlockedException.INSTANCE; } block = true; super.closeGroup(colDiff, reset, context); } };
@Test public void testDupSort() throws Exception { BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager(); GroupingNode node = getExampleGroupingNode(); node.setRemoveDuplicates(true); CommandContext context = new CommandContext("pid", "test", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$ List[] expected = new List[] { Arrays.asList(new Object[] { null, new Integer(1) }), Arrays.asList(new Object[] { new Integer(0), new Integer(1) }), Arrays.asList(new Object[] { new Integer(1), new Integer(1) }), Arrays.asList(new Object[] { new Integer(2), new Integer(2) }), Arrays.asList(new Object[] { new Integer(3), new Integer(1) }), Arrays.asList(new Object[] { new Integer(4), new Integer(2) }), Arrays.asList(new Object[] { new Integer(5), new Integer(1) }), Arrays.asList(new Object[] { new Integer(6), new Integer(2) }) }; helpProcess(mgr, node, context, expected, null); }
addBatchRow(row); if (rollup) { int rollups = orderBy.size() - colDiff; addBatchRow(row);
outputElements.add(new AggregateSymbol("SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$ outputElements.add(new AggregateSymbol("AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$ node.setElements(outputElements);
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException { // Take inputs, evaluate expressions, and build initial tuple source if(this.phase == COLLECTION) { collectionPhase(); } // If necessary, sort to determine groups (if no group cols, no need to sort) if(this.phase == SORT) { sortPhase(); } // Walk through the sorted results and for each group, emit a row if(this.phase == GROUP) { return groupPhase(); } if (this.phase == GROUP_SORT) { groupSortPhase(); } if (this.phase == GROUP_SORT_OUTPUT) { return groupSortOutputPhase(); } this.terminateBatches(); return pullBatch(); }
GroupingNode gnode = new GroupingNode(getID()); gnode.setRollup(node.hasBooleanProperty(Info.ROLLUP)); SymbolMap groupingMap = (SymbolMap)node.getProperty(NodeConstants.Info.SYMBOL_MAP); gnode.setOutputMapping(groupingMap); gnode.setRemoveDuplicates(node.hasBooleanProperty(NodeConstants.Info.IS_DUP_REMOVAL)); List<Expression> gCols = (List) node.getProperty(NodeConstants.Info.GROUP_COLS); OrderBy orderBy = (OrderBy) node.getProperty(Info.SORT_ORDER); gnode.setOrderBy(orderBy.getOrderByItems());
GroupingNode node = new GroupingNode(1); List outputElements = new ArrayList(); outputElements.add(col1); outputElements.add(new AggregateSymbol("SUM", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$ outputElements.add(new AggregateSymbol("AVG", false, bigDecimal)); //$NON-NLS-1$ //$NON-NLS-2$ node.setElements(outputElements); node.setOrderBy(new OrderBy(groupingElements).getOrderByItems()); CommandContext context = new CommandContext("pid", "test", null, null, 1); //$NON-NLS-1$ //$NON-NLS-2$
List<? extends Expression> sourceElements = this.getChildren()[0].getElements(); this.elementMap = createLookupMap(sourceElements); this.collectedExpressions = new LinkedHashMap<Expression, Integer>(); for (OrderByItem item : this.orderBy) { Expression ex = SymbolMap.getExpression(item.getSymbol()); getIndex(ex, this.collectedExpressions); getIndex(ses, collectedExpressions); functions = new AggregateFunction[getElements().size()][]; for(int i=0; i<getElements().size(); i++) { Expression symbol = getElements().get(i); if (this.outputMapping != null) { symbol = outputMapping.getMappedExpression((ElementSymbol)symbol); functions[i] = new AggregateFunction[rollup?orderBy.size()+1:1]; for (int j = 0; j < functions[i].length; j++) { functions[i][j] = initAccumulator(aggSymbol, this, this.collectedExpressions);