Spark SQL - rlike ignore case

◇◆丶佛笑我妖孽 提交于 2021-02-07 19:17:09

问题


I am using spark SQL and trying to compare a string using rlike it works fine, however would like to understand how to ignore case.

this return true

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

However, this return False,

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

回答1:


Spark is using the standard Scala regex library, so you can inline the processing flags in the pattern, for example (?i) for case-insensitive:

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|
+--------------------------------------------------------------------------------+


来源:https://stackoverflow.com/questions/57118843/spark-sql-rlike-ignore-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!