File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed
src/main/java/com/sparkTutorial/sparkSql Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -49,15 +49,16 @@ public static void main(String[] args) throws Exception {
49
49
System .out .println ("=== Print records with average mid age less than 20 ===" );
50
50
castedResponse .filter (col (AGE_MIDPOINT ).$less (20 )).show ();
51
51
52
- System .out .println ("=== Print the result with salary middle point in descending order ===" );
52
+ System .out .println ("=== Print the result by salary middle point in descending order ===" );
53
53
castedResponse .orderBy (col (SALARY_MIDPOINT ).desc ()).show ();
54
54
55
55
System .out .println ("=== Group by country and aggregate by average salary middle point and max age middle point ===" );
56
56
RelationalGroupedDataset datasetGroupByCountry = castedResponse .groupBy ("country" );
57
57
datasetGroupByCountry .agg (avg (SALARY_MIDPOINT ), max (AGE_MIDPOINT )).show ();
58
58
59
59
60
- Dataset <Row > responseWithSalaryBucket = castedResponse .withColumn (SALARY_MIDPOINT_BUCKET , col (SALARY_MIDPOINT ).divide (20000 ).cast ("integer" ).multiply (20000 ));
60
+ Dataset <Row > responseWithSalaryBucket = castedResponse .withColumn (
61
+ SALARY_MIDPOINT_BUCKET , col (SALARY_MIDPOINT ).divide (20000 ).cast ("integer" ).multiply (20000 ));
61
62
62
63
System .out .println ("=== With salary bucket column ===" );
63
64
responseWithSalaryBucket .select (col (SALARY_MIDPOINT ), col (SALARY_MIDPOINT_BUCKET )).show ();
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ public static void main(String[] args) throws Exception {
46
46
System .out .println ("=== Print responses with average mid age less than 20 ===" );
47
47
typedDataset .filter (response -> response .getAgeMidPoint () !=null && response .getAgeMidPoint () < 20 ).show ();
48
48
49
- System .out .println ("=== Print the result with salary middle point in descending order ===" );
49
+ System .out .println ("=== Print the result by salary middle point in descending order ===" );
50
50
typedDataset .orderBy (typedDataset .col (SALARY_MIDPOINT ).desc ()).show ();
51
51
52
52
System .out .println ("=== Group by country and aggregate by average salary middle point and max age middle point ===" );
@@ -56,8 +56,8 @@ public static void main(String[] args) throws Exception {
56
56
.show ();
57
57
58
58
System .out .println ("=== Group by salary bucket ===" );
59
- typedDataset .filter (response -> response .getSalaryMidPoint () != null )
60
- . map ( response -> Math .round (response .getSalaryMidPoint ()/20000 ) * 20000 , Encoders .INT ())
59
+ typedDataset .map (response -> response .getSalaryMidPoint () == null ?
60
+ null : Math .round (response .getSalaryMidPoint ()/20000 ) * 20000 , Encoders .INT ())
61
61
.withColumnRenamed ("value" , SALARY_MIDPOINT_BUCKET )
62
62
.groupBy (SALARY_MIDPOINT_BUCKET )
63
63
.count ()
You can’t perform that action at this time.
0 commit comments