将List [String]传递给采用f(args:String *)标量的函数 [英] Pass List[String] to function that takes f(args: String*) scala

查看:66
本文介绍了将List [String]传递给采用f(args:String *)标量的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用spark读取特定的实木复合地板文件,我知道可以这样做:

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")

现在我有一个List [String]对象,其中包含所有这些s3路径,但是我不知道如何将其以编程方式传递给Scala中的镶木地板函数?有很多文件可以手动执行,有什么想法如何以编程方式将文件添加到镶木地板功能中?

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?

推荐答案

我早些时候已经回答了有关重复参数的类似问题此处.

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

如@Dima所述,您正在寻找一个splat运算符,因为 .parquet 期望重复的参数:

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

sqlContext.read.parquet(listOfStrings:_*)

Scala语言规范 4.6中的重复自变量的更多信息.2

More on repeated arguments in the Scala Language Specification seciton 4.6.2

尽管这是scala 2.9的规格,但此部分没有更改.

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

这篇关于将List [String]传递给采用f(args:String *)标量的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆