Database Reference
In-Depth Information
The methods length() , min() , max() , and count() from Aggregate have con-
venience method equivalents on PCollection . Similarly, top() (as well as the de-
rived method bottom() ) and collectValues() from Aggregate , all the methods
from PTables , join() from Join , and cogroup() from Cogroup are all duplic-
ated on PTable .
The code in Example 18-4 walks through the behavior of some of the aggregation meth-
ods.
Example 18-4. Using the aggregation methods on PCollection and PTable
PCollection < String > a = MemPipeline . typedCollectionOf ( strings (),
"cherry" , "apple" , "banana" , "banana" );
assertEquals (( Long ) 4L , a . length (). getValue ());
assertEquals ( "apple" , a . min (). getValue ());
assertEquals ( "cherry" , a . max (). getValue ());
PTable < String , Long > b = a . count ();
assertEquals ( "{(apple,1),(banana,2),(cherry,1)}" , dump ( b ));
PTable < String , Long > c = b . top ( 1 );
assertEquals ( "{(banana,2)}" , dump ( c ));
PTable < String , Long > d = b . bottom ( 2 );
assertEquals ( "{(apple,1),(cherry,1)}" , dump ( d ));
Search WWH ::




Custom Search