Skip to content

Commit c7f75eb

Browse files
committed
Unwrap some flow with() examples into the normal java code.
1 parent 6362271 commit c7f75eb

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

h2o-cookbook/src/test/java/cookbook/Cookbook2.java

+24-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public static void basicStatic( Key k, Frame fr ) {
2424
doit();
2525
System.out.println(sumcols._sum+"/"+sumcols._n+" = "+(sumcols._sum/sumcols._n));
2626
System.out.println();
27+
28+
SumCol sumCol = new SumCol(year_idx);
29+
Flow.FlowPerRow<SumCol> flowPerRow = fr.with(sumCol);
30+
SumCol result = flowPerRow.doit();
31+
System.out.println("TOM: " + result._sum + " " + result._n);
2732

2833
SumCol sumcols1 = fr.
2934
with(new Flow.Filter() { public boolean filter(double ds[]) { return ds[cyl_idx]!=5; } }).
@@ -47,7 +52,25 @@ public static void basicStatic( Key k, Frame fr ) {
4752
System.out.println("Cyl="+gid._val+", "+sumcol._sum+"/"+sumcol._n+" = "+(sumcol._sum/sumcol._n));
4853
}
4954
System.out.println();
50-
55+
56+
{
57+
System.out.println("TOM ----- START");
58+
class MyGroupBy extends Flow.GroupBy {
59+
public long groupId(double ds[]) { return (long)ds[cyl_idx];}
60+
}
61+
62+
SumCol sumCol10 = new SumCol(year_idx);
63+
Flow.FlowGroupBy flowGroupBy = fr.with(new MyGroupBy());
64+
Flow.FlowGroupPerRow flowGroupPerRow = flowGroupBy.with(sumCol10);
65+
IcedHashMap<IcedLong,SumCol> hashMap = flowGroupPerRow.doit();
66+
for( IcedLong gid : hashMap.keySet() ) {
67+
SumCol sumcol = sumcols2.get(gid);
68+
System.out.println("Cyl="+gid._val+", "+sumcol._sum+"/"+sumcol._n+" = "+(sumcol._sum/sumcol._n));
69+
}
70+
System.out.println("TOM ----- END");
71+
System.out.println();
72+
}
73+
5174
IcedHashMap<IcedLong,SumCol> sumcols3 = fr.
5275
with(new Flow.Filter () { public boolean filter(double ds[]) { return ds[cyl_idx]!=5; } }).
5376
with(new Flow.GroupBy() { public long groupId ( double ds[]) { return (long)ds[cyl_idx];} }).

0 commit comments

Comments
 (0)