I have defined a regex to extract the host name from one log file as:
val host = "[a-zA-Z0-9]+\.[a-zA-Z]+\.[a-zA-Z]+".r
But when I'm trying to apply this pattern in a spark dataframe it throws an error:
df.withColumn(col("hostname"),regexp_extract("value",host,1)).show(5)
Error:
:28: error: type mismatch; found : scala.util.matching.Regex required: String df.withColumn(col("hostname"),regexp_extract("value",host,1)).show(5)
How can I apply a predefined regex pattern to the column?