Skip to content

Commit 1ce2741

Browse files
author
James Lee
committed
improve StackOverFlowSurvey
1 parent b98b1de commit 1ce2741

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

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

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

0 commit comments

Comments
 (0)