Comments by "" (@adambickford8720) on "1 Billion Rows Challenge" video.
-
Because there's always that tool that wants to do it in 1 line:
record Measurement(String station, double value) {}
stream(input.split("\n"))
.map(line -> line.split(";"))
.map(vals -> new Measurement(vals[0], Double.parseDouble(vals[1])))
.collect(collectingAndThen(
groupingBy(
Measurement::station,
collectingAndThen(
toList(),
a -> a.stream()
.mapToDouble(Measurement::value)
.summaryStatistics())),
grouped -> grouped.entrySet().stream()
.sorted(comparingByKey())
.map(entry -> "%s=%.1f/%.1f/%.1f".formatted(
entry.getKey(),
entry.getValue().getMin(),
entry.getValue().getAverage(),
entry.getValue().getMax()))
.collect(joining(", ", "{", "}"))
));
1