[英]How to pass argument to method in scala
I am trying to pass the fourth (targetFileCount) argument to a method as below我正在尝试将第四个(targetFileCount)参数传递给一个方法,如下所示
val config = ConfigFactory.load("market_opt_partition.properties")
val targetFileCount = (config.getInt(Code))
writeArray1.par.foreach {
case (df, path, tog, targetFileCount) => Utility.write(df, path, tog, targetFileCount)
}
object Utility {
def write(sourceDf: DataFrame, path: String, toggle: String, targetFileCount:Int): Unit
But I am facing the below error,但我面临以下错误,
Error:(368, 12) constructor cannot be instantiated to expected type;
found : (T1, T2, T3, T4)
required: (org.apache.spark.sql.DataFrame, String, String)
case (df, path, tog, targetFileCount) => Utility.write(df, path, tog, targetFileCount)
Error:(368, 67) not found: value df
case (df, path, tog, targetFileCount) => Utility.write(df, path, tog, targetFileCount)
Please let me know on how to rectify the same.请让我知道如何纠正同样的问题。
writeArray1
contains tuple 3 of org.apache.spark.sql.DataFrame, String, String
So pattern matching on 4 params cannot work. writeArray1
包含org.apache.spark.sql.DataFrame, String, String
元组 3 org.apache.spark.sql.DataFrame, String, String
因此 4 个参数的模式匹配无法工作。
Another example:另一个例子:
val l = List(5)
l.map { case (a, b) => a.toString }
Also yields same error:也会产生相同的错误:
error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: Int
As said above writeArray1.par contains tuple of 3 org.apache.spark.sql.DataFrame, String, String So pattern matching on 4 params cannot work.如上所述,writeArray1.par 包含 3 个 org.apache.spark.sql.DataFrame、String、String 的元组,因此 4 个参数的模式匹配无法工作。
Please use as below.请如下使用。
val config = ConfigFactory.load("market_opt_partition.properties")
val targetFileCount = (config.getInt(Code))
writeArray1.par.foreach {
case (df, path, tog) => Utility.write(df, path, tog, targetFileCount)
}
object Utility {
def write(sourceDf: DataFrame, path: String, toggle: String, targetFileCount:Int): Unit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.