Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0838a86

Browse files
authored
Update TypedDataset.scala
1 parent32838c1 commit0838a86

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
defmain(args:Array[String]) {
1313
Logger.getLogger("org").setLevel(Level.ERROR)
1414
valsession=SparkSession.builder().appName("StackOverFlowSurvey").master("local[*]").getOrCreate()
15-
importsession.implicits._
1615

1716
valdataFrameReader= 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-
valresponseWithSelectedColumns= responses.withColumn("country", responses.col("country"))
25-
.withColumn("ageMidPoint", responses.col("age_midpoint").cast("integer"))
23+
valresponseWithSelectedColumns= responses.select("country","age_midpoint","occupation","salary_midpoint")
24+
25+
valresponseWithRenamedColumns= 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-
valtypedDataset= responseWithSelectedColumns.as[Response]
31+
importsession.implicits._
32+
valtypedDataset= responseWithRenamedColumns.as[Response]
3033

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp