Skip to content

Commit 0838a86

Browse files
authored
Update TypedDataset.scala
1 parent 32838c1 commit 0838a86

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 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-
import session.implicits._
1615

1716
val dataFrameReader = session.read
1817

@@ -21,12 +20,16 @@ object TypedDataset {
2120
.option("inferSchema", value = true)
2221
.csv("in/2016-stack-overflow-survey-responses.csv")
2322

24-
val responseWithSelectedColumns = responses.withColumn("country", responses.col("country"))
25-
.withColumn("ageMidPoint", responses.col("age_midpoint").cast("integer"))
23+
val responseWithSelectedColumns = responses.select("country", "age_midpoint", "occupation", "salary_midpoint")
24+
25+
val responseWithRenamedColumns = responseWithSelectedColumns
26+
.withColumn("country", responses.col("country"))
27+
.withColumn(AGE_MIDPOINT, responses.col("age_midpoint").cast("integer"))
2628
.withColumn("occupation", responses.col("occupation"))
27-
.withColumn("salaryMidPoint", responses.col("salary_midpoint").cast("integer"))
29+
.withColumn(SALARY_MIDPOINT, responses.col("salary_midpoint").cast("integer"))
2830

29-
val typedDataset = responseWithSelectedColumns.as[Response]
31+
import session.implicits._
32+
val typedDataset = responseWithRenamedColumns.as[Response]
3033

3134
System.out.println("=== Print out schema ===")
3235
typedDataset.printSchema()

0 commit comments

Comments
 (0)