【发布时间】:2017-06-06 05:31:06
【问题描述】:
这感觉有点傻,但我正在从 Spark 1.6.1 迁移到 Spark 2.0.2。我使用的是 Databrick CSV 库,现在正在尝试使用内置的 CSV DataFrameWriter。
以下代码:
// Get an SQLContext
val sqlContext = new SQLContext(sc)
import sqlContext.implicits._
var sTS = lTimestampToSummarize.toString()
val sS3InputPath = "s3://measurements/" + sTS + "/*"
// Read all measurements - note that all subsequent ETLs will reuse dfRaw
val dfRaw = sqlContext.read.json(sS3InputPath)
// Filter just the user/segment timespent records
val dfSegments = dfRaw.filter("segment_ts <> 0").withColumn("views", lit(1))
// Aggregate views and timespent per user/segment tuples
val dfUserSegments : DataFrame = dfSegments.groupBy("company_id", "division_id", "department_id", "course_id", "user_id", "segment_id")
.agg(sum("segment_ts").alias("segment_ts_sum"), sum("segment_est").alias("segment_est_sum"), sum("views").alias("segment_views"))
// The following will write CSV files to the S3 bucket
val sS3Output = "s3://output/" + sTS + "/usersegment/"
dfUserSegments.write.csv(sS3Output)
返回此错误:
[error] /home/Spark/src/main/scala/Example.scala:75: type mismatch;
[error] found : Unit
[error] required: org.apache.spark.sql.DataFrame
[error] (which expands to) org.apache.spark.sql.Dataset[org.apache.spark.sql.Row]
[error] dfUserSegments.write.csv(sS3Output)
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 2 s, completed Jun 5, 2017 5:00:12 PM
我知道我一定是错误地解释了错误,因为我将 dfUserSegments 明确设置为 DataFrame,但编译器告诉我它是 Unit 类型(无类型)。
感谢任何帮助。
【问题讨论】:
标签: scala apache-spark dataframe