如何将二维数组传递给用户定义的函数?

How to pass two-dimensional array to User defined functions?

使用 UDF 意味着每个因子 c1c2c3 必须通过参数独立传递。是否有任何灵活的解决方案,例如如何将这些因素的序列传递给 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))

如果我这样做,编译器会说 "Not applicable":

val myFactors = dataset.select(factors.head, factors.tail: _*)

myFunction(userBias("bias"), 
           productBias("bias"),
           productBias("biases"),
           userFactors("features"), 
           productFactors("features"),
           myFactors)

如果你有这样的二维数组:

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