Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- text1 text2
- text1 text2
- import org.apache.spark.sql.functions._
- val myUDf = udf((s:String) => Array(s.trim.replaceAll(" +", " ")))
- //error: object java.lang.String is not a value --> use Array
- val data = List("i like cheese", " the dog runs ", "text111111 text2222222")
- val df = data.toDF("val")
- df.show()
- val new_df = df
- .withColumn("udfResult",myUDf(col("val")))
- .withColumn("new_val", col("udfResult")(0))
- .drop("udfResult")
- new_df.show
Add Comment
Please, Sign In to add comment