我需要使用火花更正一些拼写。 不幸的是像通过udf火花拼写校正
val misspellings3 = misspellings1
.withColumn("A", when('A === "error1", "replacement1").otherwise('A))
.withColumn("A", when('A === "error1", "replacement1").otherwise('A))
.withColumn("B", when(('B === "conditionC") and ('D === condition3), "replacementC").otherwise('B))
一个天真的做法不符合火花工作How to add new columns based on conditions (without facing JaninoRuntimeException or OutOfMemoryError)?
简单的案件(第2例),可以很好地通过
val spellingMistakes = Map(
"error1" -> "fix1"
)
val spellingNameCorrection: (String => String) = (t: String) => {
titles.get(t) match {
case Some(tt) => tt // correct spelling
case None => t // keep original
}
}
val spellingUDF = udf(spellingNameCorrection)
val misspellings1 = hiddenSeasonalities
.withColumn("A", spellingUDF('A))
处理,但我不确定如何在一个好的&一般化的方式中处理UDF中更复杂/链接的条件替换。 如果它只是一个相当小的拼写列表< 50你会建议在UDF中硬编码吗?
的确,但你的功能基本上已经在我的问题如上图所示。现在,我将使用链接解决方案,因为https://issues.apache.org/jira/browse/SPARK-18532 –