I want to use the replaceFirst() function in spark scala sql.
or
Is it possible to use the replaceFirst() function in spark scala dataframe?
Is this possible without using a UDF?
The function I want to do is:
println("abcdefgbchijkl".replaceFirst("bc","**BC**"))
// a**BC**defgbchijkl
However, the Column Type of DataFrame cannot be applied with Function:
var test0 = Seq("abcdefgbchijkl").toDF("col0")
test0
.select(col("col0").replaceFirst("bc","**BC**"))
.show(false)
/*
<console>:230: error: value replaceFirst is not a member of org.apache.spark.sql.Column
.select(col("col0").replaceFirst("bc","**BC**"))
*/
Also, I don't know how to use it in SQL form:
%sql
-- How to use replaceFirst()
select replaceFirst()