File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed
src/main/java/com/sparkTutorial/sparkSql Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -53,12 +53,17 @@ public static void main(String[] args) throws Exception {
5353 castedResponse .orderBy (col (SALARY_MIDPOINT ).desc ()).show ();
5454
5555 System .out .println ("=== Group by country and aggregate by average salary middle point and max age middle point ===" );
56- castedResponse .groupBy ("country" ).agg (avg (SALARY_MIDPOINT ), max (AGE_MIDPOINT )).show ();
56+ RelationalGroupedDataset datasetGroupByCountry = castedResponse .groupBy ("country" );
57+ datasetGroupByCountry .agg (avg (SALARY_MIDPOINT ), max (AGE_MIDPOINT )).show ();
58+
5759
58- System .out .println ("=== Group by salary bucket ===" );
5960 Dataset <Row > responseWithSalaryBucket = castedResponse .withColumn (SALARY_MIDPOINT_BUCKET , col (SALARY_MIDPOINT ).divide (20000 ).cast ("integer" ).multiply (20000 ));
60- responseWithSalaryBucket .groupBy (SALARY_MIDPOINT_BUCKET ).count ().orderBy (col (SALARY_MIDPOINT_BUCKET )).show ();
6161
62+ System .out .println ("=== With salary bucket column ===" );
63+ responseWithSalaryBucket .select (col (SALARY_MIDPOINT ), col (SALARY_MIDPOINT_BUCKET )).show ();
64+
65+ System .out .println ("=== Group by salary bucket ===" );
66+ responseWithSalaryBucket .groupBy (SALARY_MIDPOINT_BUCKET ).count ().orderBy (col (SALARY_MIDPOINT_BUCKET )).show ();
6267
6368 session .stop ();
6469 }
You can’t perform that action at this time.
0 commit comments