Skip to content

Commit b98b1de

Browse files
author
James Lee
committed
improve StackOverFlowSurvey
1 parent ce367cf commit b98b1de

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

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

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

33
import org.apache.log4j.Level;
44
import org.apache.log4j.Logger;
5-
import org.apache.spark.sql.DataFrameReader;
6-
import org.apache.spark.sql.Dataset;
7-
import org.apache.spark.sql.Row;
8-
import org.apache.spark.sql.SparkSession;
5+
import org.apache.spark.sql.*;
96

107
import static org.apache.spark.sql.functions.avg;
118
import static org.apache.spark.sql.functions.col;
@@ -39,8 +36,8 @@ public static void main(String[] args) throws Exception {
3936
responses.filter(col("country").equalTo("Afghanistan")).show();
4037

4138
System.out.println("=== Print the count of occupations ===");
42-
responses.groupBy(col("occupation")).count().show();
43-
39+
RelationalGroupedDataset groupedDataset = responses.groupBy(col("occupation"));
40+
groupedDataset.count().show();
4441

4542
System.out.println("=== Cast the salary mid point and age mid point to integer ===");
4643
Dataset<Row> castedResponse = responses.withColumn(SALARY_MIDPOINT, col(SALARY_MIDPOINT).cast("integer"))

0 commit comments

Comments
 (0)