Now i have this:
Map<String ,Map<Boolean,Long>> grouped= joinFirst.stream()
.collect(Collectors.groupingBy(t->t.get1().getLShipmode(),
partitioningBy(t-> t.get0().getOOrderpriority().equals("1-URGENT") || t.get0().getOOrderpriority().equals("2-HIGH") , counting())));
And the result is this:
MAIL false 13209
MAIL true 0
SHIP false 13224
SHIP true 0
But it should be:
MAIL false 0
MAIL true 5376
SHIP false 0
SHIP true 5346
*The order in which elements are returned when the stream is eventually
* consumed <em>is unspecified</em>. The order may even change from one
* invocation to another. Thus, it is an error to assume any particular
* element order even though is might appear, for some stream sources, that
* there is a de-facto order.
* <p>
* If a deterministic order is required, then make sure to invoke the
* {@link Stream#sorted(java.util.Comparator)} method on the {@link Stream}
* returned.
* <p>
sorted()
operation if you need a deterministic order (this will cost performance though).
But the results are very different. For example, this query in Postgresql:
select
l_returnflag,
l_linestatus,
sum(l_extendedprice) as sum_charge,
avg(l_tax)
from
lineitem
where
l_shipdate <= date '1998-12-01'
group by
l_returnflag,
l_linestatus
order by
l_returnflag,
l_linestatus;
With the speedment the output is this:
A F 1,20E+10 0,039955076
N F 3,23E+08 0,040103375
N O 1,91E+10 0,040013735
R F 1,20E+10 0,039975758
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_MONTH,1);
cal.set(Calendar.MONTH,Calendar.DECEMBER);
cal.set(Calendar.YEAR,1998);
java.sql.Date sqlDate = new java.sql.Date(cal.getTimeInMillis());
LineitemManager lineitem = app.getOrThrow(LineitemManager.class);
Map<Tuple2<String, String>, AbstractMap.SimpleEntry<Double, Double>> grouped = lineitem.stream().filter(Lineitem.L_SHIPDATE.lessOrEqual(sqlDate))
.collect(groupingBy(t->Tuples.of(t.getLReturnflag(), t.getLLinestatus()),
Collectors.collectingAndThen(Collectors.toList(),
list-> {double first =
list
.stream()
.mapToDouble(t -> t.getLExtendedprice().get().doubleValue()).sum();
double second =
list
.stream()
.collect(averagingDouble(t->t.getLTax().get().doubleValue()));
return new AbstractMap.SimpleEntry<>(first, second);})
));
grouped.forEach((key, value) -> System.out.println(key + ", " + value));
.mapToDouble (t -> t.getLExtendedprice (). Get (). DoubleValue ()). Sum ();
.mapToDouble (t -> t.getLExtendedprice (). DoubleValue ()). Sum () ;
. And the second machine needs get ()
before doubleValue ()