Guest User

Untitled

a guest
Jun 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. text1 text2
  2.  
  3. text1 text2
  4.  
  5. import org.apache.spark.sql.functions._
  6.  
  7. val myUDf = udf((s:String) => Array(s.trim.replaceAll(" +", " ")))
  8. //error: object java.lang.String is not a value --> use Array
  9.  
  10. val data = List("i like cheese", " the dog runs ", "text111111 text2222222")
  11. val df = data.toDF("val")
  12. df.show()
  13.  
  14. val new_df = df
  15. .withColumn("udfResult",myUDf(col("val")))
  16. .withColumn("new_val", col("udfResult")(0))
  17. .drop("udfResult")
  18. new_df.show
Add Comment
Please, Sign In to add comment