Scala 如何将udf应用于Dafaframe上的所有字符串和字符串数组

Scala 如何将udf应用于Dafaframe上的所有字符串和字符串数组,scala,apache-spark,Scala,Apache Spark,我有一个简单的自定义项,用于大写所有字符串 val upper = (s: String) => { s.toUpperCase } val upperUDF: UserDefinedFunction = spark.udf.register("upper", upper) 我试图像这样使用UDF,这样我可以得到所有大写的字符串,所有字符串都是嵌套模式 def extractNames(schema: StructType): Seq[

我有一个简单的自定义项,用于大写所有字符串

 val upper = (s: String) => {
        s.toUpperCase

  }

 val upperUDF: UserDefinedFunction = spark.udf.register("upper", upper)
我试图像这样使用UDF,这样我可以得到所有大写的字符串,所有字符串都是嵌套模式

  def extractNames(schema: StructType): Seq[String] = {
    schema.fields.flatMap { field =>
      field.dataType match {
        case structType: StructType =>
          extractNames(structType).map(field.name + "." + _)
        case _: StringType =>
          field.name :: Nil
        case s: ArrayType if (s.elementType == StringType) =>
          field.name + "." + "element" :: Nil
        case _ =>
          Nil
      }
    }
  }

  extractNames(df.schema)
      .foldLeft(df)({ (memoDF, colName) =>
        memoDF.withColumn(colName, upperUDF(col(colName)))
      })
      .as[B]
但是当我得到一个字符串数组时,我有这个错误


cannot resolve '`alert`['element']' due to data type mismatch: argument 2 requires integral type, however, ''element'' is of string type.;;


alert是一个字符串数组

您能否举例说明输入数据帧的外观以及您希望输出的内容?

cannot resolve '`alert`['element']' due to data type mismatch: argument 2 requires integral type, however, ''element'' is of string type.;;