cry*_*ryp 7 scala dataframe apache-spark
当我使用udf通过分隔符在列中拆分字符串时,我一直收到错误.我正在使用Scala
Error: java.lang.ClassCastException: $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$anonfun$1 cannot be cast to scala.Function2
Run Code Online (Sandbox Code Playgroud)
不知道这是什么以及如何解决它.
这是我的udf和数据框架:
val rsplit = udf((refsplit: String) => refsplit.split(":"))
+---------+--------------------+--------------------+
| user| jsites| jsites1|
+---------+--------------------+--------------------+
|123ashish|m.mangahere.co:m....|m.mangahere.co:m....|
|456ashish|m.mangahere2.co:m...|m.mangahere2.co:m...|
| ashish|m.mangahere.co:m....|m.mangahere.co:m....|
+---------+--------------------+--------------------+
Run Code Online (Sandbox Code Playgroud)
列jsites看起来像m.manghere.co:m.facebook.com:.msn.com.而我试图使用UDF分裂m.manghere.co:m.facebook.com:.msn.com的:.
我一直在收到这个错误
Chi*_*rma -1
提供了一个 split 函数org.apache.spark.sql.functions
import org.apache.spark.sql.functions.{col,split}
val df = ???
df.withColumn("split sites",split(col("COLNAME"), "REGEX"))
Run Code Online (Sandbox Code Playgroud)
这些问题有点老了,希望这对其他人有帮助。干杯