File tree Expand file tree Collapse file tree 1 file changed +4
-0
lines changed
src/main/java/com/sparkTutorial/sparkSql Expand file tree Collapse file tree 1 file changed +4
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ public class StackOverFlowSurvey {
1414
1515 private static final String AGE_MIDPOINT = "age_midpoint" ;
1616 private static final String SALARY_MIDPOINT = "salary_midpoint" ;
17+ public static final String SALARY_MIDPOINT_BUCKET = "salary_midpoint_bucket" ;
1718
1819 public static void main (String [] args ) throws Exception {
1920
@@ -57,5 +58,8 @@ public static void main(String[] args) throws Exception {
5758 System .out .println ("=== Group by country and aggregate by average salary middle point and max age middle point ===" );
5859 castedResponse .groupBy ("country" ).agg (avg (SALARY_MIDPOINT ), max (AGE_MIDPOINT )).show ();
5960
61+ System .out .println ("=== Group by salary bucket ===" );
62+ Dataset <Row > responseWithSalaryBucket = castedResponse .withColumn (SALARY_MIDPOINT_BUCKET , new Column (SALARY_MIDPOINT ).divide (20000 ).cast ("integer" ).multiply (20000 ));
63+ responseWithSalaryBucket .groupBy (SALARY_MIDPOINT_BUCKET ).count ().orderBy (new Column (SALARY_MIDPOINT_BUCKET )).show ();
6064 }
6165}
You can’t perform that action at this time.
0 commit comments