File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed
src/main/java/com/sparkTutorial/sparkSql Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
import org .apache .log4j .Level ;
4
4
import org .apache .log4j .Logger ;
5
+ import org .apache .spark .api .java .function .FilterFunction ;
5
6
import org .apache .spark .sql .*;
6
7
7
8
import static org .apache .spark .sql .functions .avg ;
@@ -38,19 +39,21 @@ public static void main(String[] args) throws Exception {
38
39
typedDataset .show (20 );
39
40
40
41
System .out .println ("=== Print the responses from Afghanistan ===" );
41
- typedDataset .filter (response -> response .getCountry ().equals ("Afghanistan" )).show ();
42
+ typedDataset .filter (( FilterFunction < Response >) response -> response .getCountry ().equals ("Afghanistan" )).show ();
42
43
43
44
System .out .println ("=== Print the count of occupations ===" );
44
45
typedDataset .groupBy (typedDataset .col ("occupation" )).count ().show ();
45
46
46
47
System .out .println ("=== Print responses with average mid age less than 20 ===" );
47
- typedDataset .filter (response -> response .getAgeMidPoint () !=null && response .getAgeMidPoint () < 20 ).show ();
48
+ typedDataset .filter ((FilterFunction <Response >)response -> response .getAgeMidPoint () !=null &&
49
+ response .getAgeMidPoint () < 20 )
50
+ .show ();
48
51
49
52
System .out .println ("=== Print the result by salary middle point in descending order ===" );
50
53
typedDataset .orderBy (typedDataset .col (SALARY_MIDPOINT ).desc ()).show ();
51
54
52
55
System .out .println ("=== Group by country and aggregate by average salary middle point and max age middle point ===" );
53
- typedDataset .filter (response -> response .getSalaryMidPoint () != null )
56
+ typedDataset .filter (( FilterFunction < Response >) response -> response .getSalaryMidPoint () != null )
54
57
.groupBy ("country" )
55
58
.agg (avg (SALARY_MIDPOINT ), max (AGE_MIDPOINT ))
56
59
.show ();
You can’t perform that action at this time.
0 commit comments