gpt4 book ai didi

scala - 如何将路径列表传递给 spark.read.load?

转载 作者:行者123 更新时间:2023-12-01 08:22:34 25 4
gpt4 key购买 nike

我可以通过将多个路径传递给 load 来一次加载多个文件方法,例如

spark.read
.format("com.databricks.spark.avro")
.load(
"/data/src/entity1/2018-01-01",
"/data/src/entity1/2018-01-12",
"/data/src/entity1/2018-01-14")

我想先准备一个路径列表并将它们传递给 load方法,但我收到以下编译错误:
val paths = Seq(
"/data/src/entity1/2018-01-01",
"/data/src/entity1/2018-01-12",
"/data/src/entity1/2018-01-14")
spark.read.format("com.databricks.spark.avro").load(paths)

<console>:29: error: overloaded method value load with alternatives:
(paths: String*)org.apache.spark.sql.DataFrame <and>
(path: String)org.apache.spark.sql.DataFrame
cannot be applied to (List[String])spark.read.format("com.databricks.spark.avro").load(paths)

为什么?如何将路径列表传递给 load方法?

最佳答案

您只需要一个 splat 运算符 ( _* ) paths列为

spark.read.format("com.databricks.spark.avro").load(paths: _*)

关于scala - 如何将路径列表传递给 spark.read.load?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50890344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com