Pass List[String] to function that takes f(args: String*) scala

依然范特西╮ 提交于 2020-01-07 03:02:50

问题


I need to read in specific parquet files with spark, I know this can be done like so:

sqlContext
    .read
    .parquet("s3://bucket/key", "s3://bucket/key")

Right now I have a List[String] object with all these s3 paths in it but I don't know how I can pass this programmatically to the parquet function in Scala? There are way to many files to do it manually, any ideas how to get the files into the parquet function programmatically?


回答1:


I've answer a similar question earlier concerning repeated parameters here.

As @Dima mentioned, you are looking for a splat operator because .parquet expected repeated arguments :

sqlContext.read.parquet(listOfStrings:_*)

More on repeated arguments in the Scala Language Specification seciton 4.6.2

Although it's the specs of scala 2.9, this part didn't change.



来源:https://stackoverflow.com/questions/38258023/pass-liststring-to-function-that-takes-fargs-string-scala

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!