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 {
4949 System .out .println ("=== Print records with average mid age less than 20 ===" );
5050 castedResponse .filter (col (AGE_MIDPOINT ).$less (20 )).show ();
5151
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 ===" );
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 ===" );
5656 RelationalGroupedDataset datasetGroupByCountry = castedResponse .groupBy ("country" );
5757 datasetGroupByCountry .agg (avg (SALARY_MIDPOINT ), max (AGE_MIDPOINT )).show ();
5858
5959
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 ));
6162
6263 System .out .println ("=== With salary bucket column ===" );
6364 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 {
4646 System .out .println ("=== Print responses with average mid age less than 20 ===" );
4747 typedDataset .filter (response -> response .getAgeMidPoint () !=null && response .getAgeMidPoint () < 20 ).show ();
4848
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 ===" );
5050 typedDataset .orderBy (typedDataset .col (SALARY_MIDPOINT ).desc ()).show ();
5151
5252 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 {
5656 .show ();
5757
5858 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 ())
6161 .withColumnRenamed ("value" , SALARY_MIDPOINT_BUCKET )
6262 .groupBy (SALARY_MIDPOINT_BUCKET )
6363 .count ()
You can’t perform that action at this time.
0 commit comments