I'm investigating the use of cqengine as the cost of re querying the database would be too costly, but I'm really struggling to retrieve the data I need.
IndexedCollection<PnLRow> rows = CQEngine.newInstance();
rows.addIndex(NavigableIndex.onAttribute(PnLRow.STRATEGY));
rows.addIndex(NavigableIndex.onAttribute(PnLRow.SUBSTRATEGY));
rows.add(new PnLRow("Commodities", "Directional", "Brent", "COMMODITIES", 1, 1, 1, 1, 1, 1, 1, 1));
rows.add(new PnLRow("Commodities", "Directional", "Brent", "FX", 1, 1, 1, 1, 1, 1, 1, 1));
rows.add(new PnLRow("Commodities", "Directional", "Copper", "COMMODITIES", 1, 1, 1, 1, 1, 1, 1, 1));
rows.add(new PnLRow("Commodities", "Directional", "Copper", "FX", 1, 1, 1, 1, 1, 1, 1, 1));
rows.add(new PnLRow("FX", "Directional", "CAD", "FX", 1, 1, 1, 1, 1, 1, 1, 1));
rows.add(new PnLRow("FX", "Directional", "CHF", "FX", 1, 1, 1, 1, 1, 1, 1, 1));
In SQL I'd like to
select strategy, sum(num1),sum(num2)...etc
from tblname
group by strategy
Every example I come across, shows me how to do this for one field
Map<String, Double> grpx = rows.stream().collect(Collectors.groupingBy(PnLRow::getStratName, Collectors.summingDouble(PnLRow::getDaily)));
Which returns
{FX=2.0, Commodities=4.0}
Is it possible to do it for all fields, or am I approaching this completely incorrectly
Edit:
Example output I'd like would be
{ {fx=2.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0}, {Commodities=4.0,4.0,4.0,4.0,4.0,4.0,4.0,4.0} }