@@ -12,7 +12,6 @@ object TypedDataset {
1212def main (args :Array [String ]) {
1313Logger .getLogger(" org" ).setLevel(Level .ERROR )
1414val session = SparkSession .builder().appName(" StackOverFlowSurvey" ).master(" local[*]" ).getOrCreate()
15- import session .implicits ._
1615
1716val 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
3134System .out.println(" === Print out schema ===" )
3235 typedDataset.printSchema()