Skip to content

Commit 1c4966f

Browse files
author
James Lee
committed
add salary bucket
1 parent d226bf2 commit 1c4966f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/main/java/com/sparkTutorial/sparkSql/StackOverFlowSurvey.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)