Apache Spark startsWith in SQL expression
With regexp_replace, you can get the same results without UDFs. Check this out
scala> val df=Seq(("bPREFIX",1),("PREFIXb",2)).toDF("a","b")
df: org.apache.spark.sql.DataFrame = [a: string, b: int]
scala> df.show
+-------+---+
| a| b|
+-------+---+
|bPREFIX| 1|
|PREFIXb| 2|
+-------+---+
scala> df.filter(regexp_replace('a,"""^PREFIX.*""","")==="").show
+-------+---+
| a| b|
+-------+---+
|PREFIXb| 2|
+-------+---+
scala>
or using regexp_extract()
scala> df.filter(regexp_extract('a,"""(^PREFIX)""",1)==="PREFIX").show
+-------+---+
| a| b|
+-------+---+
|PREFIXb| 2|
+-------+---+
scala>
Using instr() function
scala> df.filter("instr(a,'PREFIX')=1").show
+-------+---+
| a| b|
+-------+---+
|PREFIXb| 2|
+-------+---+
scala>
I found the following solution that works with Spark SQL query without custom UDP and out of the box, for example:
CASE WHEN instr(PRICE_SOURCE_INDICATOR,'MAC') = 1