Skip to content

Commit 69ee9eb

Browse files
author
James Lee
committed
update TypedDataset
1 parent 91074f5 commit 69ee9eb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.log4j.Level;
44
import org.apache.log4j.Logger;
5+
import org.apache.spark.api.java.function.FilterFunction;
56
import org.apache.spark.sql.*;
67

78
import static org.apache.spark.sql.functions.avg;
@@ -38,19 +39,21 @@ public static void main(String[] args) throws Exception {
3839
typedDataset.show(20);
3940

4041
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();
4243

4344
System.out.println("=== Print the count of occupations ===");
4445
typedDataset.groupBy(typedDataset.col("occupation")).count().show();
4546

4647
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();
4851

4952
System.out.println("=== Print the result by salary middle point in descending order ===");
5053
typedDataset.orderBy(typedDataset.col(SALARY_MIDPOINT ).desc()).show();
5154

5255
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)
5457
.groupBy("country")
5558
.agg(avg(SALARY_MIDPOINT), max(AGE_MIDPOINT))
5659
.show();

0 commit comments

Comments
 (0)