Skip to content

Commit 2590f99

Browse files
authored
Update TypedDataset.scala
1 parent e714a9f commit 2590f99

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ object TypedDataset {
1212
def main(args: Array[String]) {
1313
Logger.getLogger("org").setLevel(Level.ERROR)
1414
val session = SparkSession.builder().appName("StackOverFlowSurvey").master("local[*]").getOrCreate()
15-
1615
val dataFrameReader = session.read
1716

1817
val responses = dataFrameReader
@@ -22,14 +21,8 @@ object TypedDataset {
2221

2322
val responseWithSelectedColumns = responses.select("country", "age_midpoint", "occupation", "salary_midpoint")
2423

25-
val responseWithRenamedColumns = responseWithSelectedColumns
26-
.withColumn("country", responses.col("country"))
27-
.withColumn(AGE_MIDPOINT, responses.col(AGE_MIDPOINT).cast("integer"))
28-
.withColumn("occupation", responses.col("occupation"))
29-
.withColumn(SALARY_MIDPOINT, responses.col(SALARY_MIDPOINT).cast("integer"))
30-
3124
import session.implicits._
32-
val typedDataset = responseWithRenamedColumns.as[Response]
25+
val typedDataset = responseWithSelectedColumns.as[Response]
3326

3427
System.out.println("=== Print out schema ===")
3528
typedDataset.printSchema()
@@ -44,7 +37,7 @@ object TypedDataset {
4437
typedDataset.groupBy(typedDataset.col("occupation")).count().show()
4538

4639
System.out.println("=== Print responses with average mid age less than 20 ===")
47-
typedDataset.filter(response => response.age_midpoint.isDefined && response.age_midpoint.get < 20).show()
40+
typedDataset.filter(response => response.age_midpoint.isDefined && response.age_midpoint.get < 20.0).show()
4841

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

0 commit comments

Comments
 (0)