- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在准备一个带有 id 和我的特征向量的 DataFrame,以便稍后用于进行预测。我在我的数据框上做了一个 groupBy,在我的 groupBy 中,我将几列作为列表合并到一个新列中:
def mergeFunction(...) // with 14 input variables
val myudffunction( mergeFunction ) // Spark doesn't support this
df.groupBy("id").agg(
collect_list(df(...)) as ...
... // too many of these (something like 14 of them)
).withColumn("features_labels",
myudffunction(
col(...)
, col(...) )
.select("id", "feature_labels")
I am not sure how else I can fix this? Is the size of udf inputs in Spark going to get bigger, am have I understood them incorrectly, or there is a better way?
最佳答案
用户定义的函数最多可定义 22 个参数。仅限 udf
helper 最多为 10 个参数定义。要处理具有大量参数的函数,您可以使用 org.apache.spark.sql.UDFRegistration
.
例如
val dummy = ((
x0: Int, x1: Int, x2: Int, x3: Int, x4: Int, x5: Int, x6: Int, x7: Int,
x8: Int, x9: Int, x10: Int, x11: Int, x12: Int, x13: Int, x14: Int,
x15: Int, x16: Int, x17: Int, x18: Int, x19: Int, x20: Int, x21: Int) => 1)
import org.apache.spark.sql.expressions.UserDefinedFunction
val dummyUdf: UserDefinedFunction = spark.udf.register("dummy", dummy)
val df = spark.range(1)
val exprs = (0 to 21).map(_ => lit(1))
df.select(dummyUdf(exprs: _*))
callUdf
点名
import org.apache.spark.sql.functions.callUDF
df.select(
callUDF("dummy", exprs: _*).alias("dummy")
)
df.selectExpr(s"""dummy(${Seq.fill(22)(1).mkString(",")})""")
UserDefinedFunction
目的:
import org.apache.spark.sql.expressions.UserDefinedFunction
Seq(1).toDF.select(UserDefinedFunction(dummy, IntegerType, None)(exprs: _*))
array
,
map
)或
struct
作为输入或将其分为多个模块。例如:
val aLongArray = array((0 to 256).map(_ => lit(1)): _*)
val udfWitharray = udf((xs: Seq[Int]) => 1)
Seq(1).toDF.select(udfWitharray(aLongArray).alias("dummy"))
关于scala - 当 udf 函数不接受足够大的输入变量时 Spark DataFrames,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39494620/
对于我的问题,我找不到更好的措辞。 在我的应用程序中的某个时刻,我设置了一些非常密集的动画。问题是,在高端设备上,动画运行流畅且赏心悦目。另一方面,我测试过的一台低端设备在制作动画时表现非常糟糕。 试
我正在修补 OTP 模块 ( yubico_pam ),并尝试访问管理员选择的控制标志(例如必需,足够, ETC)。 有什么想法吗?这是否可行(无需解析文件)? 最佳答案 无法在 API 中查询此信息
我有一些为 Linux 编写的 C 代码,依赖于套接字和 arpa/inet.h 以及 libusb.h,我想在 MinGW 下为 Windows 编译它。 (请注意,当前项目只有一个非常简单的 Ma
我是一名优秀的程序员,十分优秀!