GroupTask implements Task { @Override public ExecutionResult execute(ExecutionResult previousTaskResult) throws SQLException { try { DataContainer dataContainer = new DataContainer(previousTaskResult.getData(), rows -> { List<DataRow> data = previousTaskResult.getData().getRows(); Map<List<Object>, List<DataRow>> initialMap = new HashMap<List<Object>, List<DataRow>>(){ { put(new ArrayList<>(), data); } }; return groupData(initialMap, expressions) .values().stream().map(v -> v.get(0)) .collect(Collectors.toList()); }); return new ExecutionResult(){ { setCount(dataContainer.getRows().size()); setData(dataContainer); } }; } catch (Exception e) { throw new SQLException(e); } } @Autowired  GroupTask(ExpressionEvaluator expressionEvaluator); void addExpression(Object expression); @Override ExecutionResult execute(ExecutionResult previousTaskResult); List<Object> getExpressions(); @Override String toString();  }
@Test public void testExecute() throws Exception { ExecutionResult output = groupBy(false); assertThat(output.getCount(), equalTo(3)); List<DataRow> data = output.getData().getRows(); assertThat(data, hasSize(3)); List<List<?>> dataRows = data.stream() .map(DataRow::getValues) .collect(Collectors.toList()); assertThat(dataRows, containsInAnyOrder( createRow("one", 1), createRow("two", 1), createRow("two", 2) )); }