我有如下的List [String]
val colList = List(verifyLength($"col1", lit(0), lit(0), lit("RJ"), lit(9)).as("col1"), verifyLength($"col2", lit(0), lit(0), lit("RJ"), lit(16)).as("col2"))
在尝试对以下数据框应用选择时
val selDataDf = df.select(colList.head, colList.tail: _*)
我遇到了例外情况-org.apache.spark.sql.AnalysisException: cannot resolve '`verifyLength($"col1", lit(0), lit(0), lit("RJ"), lit(9)).as("col1")`' given input columns:
如果我像下面那样传递字符串,这就是选择语句的结果。
val selDataDf = df.select(verifyLength($"col1", lit(0), lit(0), lit("RJ"), lit(9)).as("col1"), verifyLength($"col2", lit(0), lit(0), lit("RJ"), lit(16)).as("col2"))
注意:“ verifyLength”是用户定义的udf。
答案 0 :(得分:0)
我找到了它不起作用的原因,
您可以像下面那样传递List [String]:
val detailsList = List(verifyLength(col1, 0, 0, 'RJ', 9) as col1, verifyLength(col2, 0, 0, 'RJ', 9) as col2)
spark.udf.register("verifyLength", verifyLengthCheck _)
val df1= df.selectExpr(detailsList:_*)
请遵循以下网址:enter link description here