使用UDF意味着每个因子c1
,c2
,c3
必须由参数独立传递。有没有灵活的解决方案,例如如何将这些因素的序列传递给 UDF ?
val myFunction = udf {
(userBias: Float, productBias: Float, productBiases: Map[Long, Float],
userFactors: Seq[Float], productFactors: Seq[Float], c1: String, c2: String, c3: String) =>
var result = Float.NaN
// result calculation
result
}
然后我按以下方式调用此函数(dataset
是DataFrame
):
myFunction(userBias("bias"),
productBias("bias"),
productBias("biases"),
userFactors("features"),
productFactors("features"),
dataset(factors(0)), dataset(factors(1)), dataset(factors(2))
如果我这样做,那么编译器会说“不适用”:
val myFactors = dataset.select(factors.head, factors.tail: _*)
myFunction(userBias("bias"),
productBias("bias"),
productBias("biases"),
userFactors("features"),
productFactors("features"),
myFactors)
答案 0 :(得分:2)
如果您有这样的二维数组:
val xy = Array.ofDim[Int](numrows, numcolumns);
isFunction(xy);
isFunction的函数定义如下所示:
def isFunction(arg: Array[Array[Int]]){
println(arg(i)(0)); // how to access array element