@Test public void testBlocking() throws Exception { BufferManager mgr = BufferManagerFactory.getStandaloneBufferManager(); ElementSymbol bigDecimal = new ElementSymbol("value"); bigDecimal.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL); GroupingNode node = new GroupingNode(1) { boolean block = true; @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); } }; List outputElements = new ArrayList(); outputElements.add(new AggregateSymbol("SUM", false, bigDecimal)); outputElements.add(new AggregateSymbol("AVG", false, bigDecimal)); node.setElements(outputElements); CommandContext context = new CommandContext("pid", "test", null, null, 1); List[] data = new List[] { Arrays.asList(new Object[] { new BigDecimal("0.0") }), Arrays.asList(new Object[] { new BigDecimal("1.0") }), Arrays.asList(new Object[] { new BigDecimal("2.0") }), Arrays.asList(new Object[] { new BigDecimal("3.0") }), Arrays.asList(new Object[] { new BigDecimal("4.0") }) }; List[] expected = new List[] { Arrays.asList(new Object[] { new BigDecimal("10.0"), new BigDecimal("2.0") }) }; List symbols = new ArrayList(); symbols.add(bigDecimal); FakeTupleSource dataSource = new FakeTupleSource(symbols, data) { boolean end; @Override public List nextTuple() throws TeiidComponentException { List result = super.nextTuple(); if (end) { fail(); } end = result == null; return result; } }; helpProcess(mgr, node, context, expected, dataSource, null); }
protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { row.add( functions[i][0].getResult(context) ); if (reset && !rollup) { functions[i][0].reset(); } } addBatchRow(row); if (rollup) { int rollups = orderBy.size() - colDiff; for (int j = 1; j < rollups; j++) { row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { if (functions[i].length == 1) { int index = functions[i][0].getArgIndexes()[0]; Integer val = this.indexMap.get(index); if (val != null && val <= j) { row.add(null); } else { row.add(functions[i][0].getResult(context)); } } else { row.add( functions[i][j].getResult(context) ); if (reset) { functions[i][j].reset(); } } } addBatchRow(row); } if (reset) { for(int i=0; i<functions.length; i++) { functions[i][0].reset(); } } } }
GroupingNode extends SubqueryAwareRelationalNode { protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { row.add( functions[i][0].getResult(context) ); if (reset && !rollup) { functions[i][0].reset(); } } addBatchRow(row); if (rollup) { int rollups = orderBy.size() - colDiff; for (int j = 1; j < rollups; j++) { row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { if (functions[i].length == 1) { int index = functions[i][0].getArgIndexes()[0]; Integer val = this.indexMap.get(index); if (val != null && val <= j) { row.add(null); } else { row.add(functions[i][0].getResult(context)); } } else { row.add( functions[i][j].getResult(context) ); if (reset) { functions[i][j].reset(); } } } addBatchRow(row); } if (reset) { for(int i=0; i<functions.length; i++) { functions[i][0].reset(); } } } } }
GroupingNode extends SubqueryAwareRelationalNode { protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { row.add( functions[i][0].getResult(context) ); if (reset && !rollup) { functions[i][0].reset(); } } addBatchRow(row); if (rollup) { int rollups = orderBy.size() - colDiff; for (int j = 1; j < rollups; j++) { row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { if (functions[i].length == 1) { int index = functions[i][0].getArgIndexes()[0]; Integer val = this.indexMap.get(index); if (val != null && val <= j) { row.add(null); } else { row.add(functions[i][0].getResult(context)); } } else { row.add( functions[i][j].getResult(context) ); if (reset) { functions[i][j].reset(); } } } addBatchRow(row); } if (reset) { for(int i=0; i<functions.length; i++) { functions[i][0].reset(); } } } } GroupingNode(int nodeID); }
GroupingNode extends SubqueryAwareRelationalNode { protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { row.add( functions[i][0].getResult(context) ); if (reset && !rollup) { functions[i][0].reset(); } } addBatchRow(row); if (rollup) { int rollups = orderBy.size() - colDiff; for (int j = 1; j < rollups; j++) { row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { if (functions[i].length == 1) { int index = functions[i][0].getArgIndexes()[0]; Integer val = this.indexMap.get(index); if (val != null && val <= j) { row.add(null); } else { row.add(functions[i][0].getResult(context)); } } else { row.add( functions[i][j].getResult(context) ); if (reset) { functions[i][j].reset(); } } } addBatchRow(row); } if (reset) { for(int i=0; i<functions.length; i++) { functions[i][0].reset(); } } } } GroupingNode(int nodeID); void reset(); void setRemoveDuplicates(boolean removeDuplicates); void setOrderBy(List<OrderByItem> orderBy); void setOutputMapping(SymbolMap outputMapping); @Override void initialize(CommandContext context, BufferManager bufferManager,
            ProcessorDataManager dataMgr); TupleBatch nextBatchDirect(); TupleSource getGroupSortTupleSource(); @Override Collection<? extends LanguageObject> getObjects(); static int sameGroup(int[] indexes, List<?> newTuple, List<?> oldTuple); void closeDirect(); Object clone(); PlanNode getDescriptionProperties(); void setRollup(boolean rollup); }
GroupingNode extends SubqueryAwareRelationalNode { protected void closeGroup(int colDiff, boolean reset, CommandContext context) throws FunctionExecutionException, ExpressionEvaluationException, TeiidComponentException, TeiidProcessingException { List<Object> row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { row.add( functions[i][0].getResult(context) ); if (reset && !rollup) { functions[i][0].reset(); } } addBatchRow(row); if (rollup) { int rollups = orderBy.size() - colDiff; for (int j = 1; j < rollups; j++) { row = new ArrayList<Object>(functions.length); for(int i=0; i<functions.length; i++) { if (functions[i].length == 1) { int index = functions[i][0].getArgIndexes()[0]; Integer val = this.indexMap.get(index); if (val != null && val <= j) { row.add(null); } else { row.add(functions[i][0].getResult(context)); } } else { row.add( functions[i][j].getResult(context) ); if (reset) { functions[i][j].reset(); } } } addBatchRow(row); } if (reset) { for(int i=0; i<functions.length; i++) { functions[i][0].reset(); } } } } GroupingNode(int nodeID); void reset(); void setRemoveDuplicates(boolean removeDuplicates); void setOrderBy(List<OrderByItem> orderBy); void setOutputMapping(SymbolMap outputMapping); @Override void initialize(CommandContext context, BufferManager bufferManager,
            ProcessorDataManager dataMgr); TupleBatch nextBatchDirect(); TupleSource getGroupSortTupleSource(); @Override Collection<? extends LanguageObject> getObjects(); static int sameGroup(int[] indexes, List<?> newTuple, List<?> oldTuple); void closeDirect(); Object clone(); PlanNode getDescriptionProperties(); void setRollup(boolean rollup);  }