Spark SQL-Rlike忽略大小写

时间:2019-07-19 19:44:44

标签: apache-spark apache-spark-sql

我正在使用spark SQL,并尝试使用rlike比较字符串,它可以正常工作,但是想了解如何忽略大小写。

此返回true

select "1 Week Ending Jan 14, 2018" rlike "^\\d+ Week Ending [a-z, A-Z]{3} \\d{2}, \\d{4}"

但是,此返回False,

select "1 Week Ending Jan 14, 2018" rlike "^\\d+ week ending [a-z, A-Z]{3} \\d{2}, \\d{4}"

1 个答案:

答案 0 :(得分:0)

Spark使用标准的Scala regex库,因此您可以内嵌模式中的处理标记,例如,不区分大小写的(?i)

spark.sql("""select "1 Week Ending Jan 14, 2018" rlike "(?i)^\\d+ week ending [a-z, A-Z]{3} \\d{2}, \\d{4}"""").show()
+--------------------------------------------------------------------------------+
|1 Week Ending Jan 14, 2018 RLIKE (?i)^\d+ week ending [a-z, A-Z]{3} \d{2}, \d{4}|
+--------------------------------------------------------------------------------+
|                                                                            true|
+--------------------------------------------------------------------------------+