Spark SQL,正则,regexp_replace

val simpleColors=Seq("black","white","red","green","blue")
val regexString=simpleColors.map(_.toUpperCase).mkString("|")
df.select(regexp_replace(col("Description"),regexString,"COLOR")
.as("color_clean"),col("Description"))
.show(2)
spark.sql("select regexp_replace(Description,'black|white|red|green|blue','COLOR') 
as color_clean,Description from dfTable ").show(2)

你可能感兴趣的:(Spark SQL,正则,regexp_replace)