|
2 | 2 |
|
3 | 3 | importorg.apache.log4j.Level;
|
4 | 4 | importorg.apache.log4j.Logger;
|
| 5 | +importorg.apache.spark.api.java.function.FilterFunction; |
5 | 6 | importorg.apache.spark.sql.*;
|
6 | 7 |
|
7 | 8 | importstaticorg.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();
|
|