【问题标题】:Hive: Regex for backslashHive:反斜杠的正则表达式
【发布时间】:2015-01-24 13:43:44
【问题描述】:

我需要查询所有中间有反斜杠字符的行。这是我写的查询:

select * from table where A = '2014-10-30' and B rlike '.asterisk\.asterisk'

(必须手动输入星号。查询本身就有符号)

无论B列是否有反斜杠,它都会返回整个表格。

'.\\.' 没有返回任何行,即使有些行 B 具有反斜杠字符。

样品 B - 您好可以为您查看详细信息/

【问题讨论】:

  • 您的示例中没有反斜杠。

标签: regex hadoop hive hiveql


【解决方案1】:
select regexp_replace(datecolumn,'-','\\') as dt from tablename;

【讨论】:

    【解决方案2】:

    这是编写正则表达式的基本指南:http://tldp.org/LDP/Bash-Beginners-Guide/html/chap_04.html

    如果你需要检查字符串中是否有反斜杠,试试“instr”函数,它更简单 tran regexp:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-StringFunctions

    对于正则表达式,它应该是这样的:'\\'

    另一个在线检查正则表达式有效性的好资源:http://regex101.com/

    【讨论】:

      【解决方案3】:

      这个问题在这篇博文中有很好的解释。

      https://www.themarketingtechnologist.co/slashception-with-regexp_extract-in-hive/.

      简而言之,答案是:

      使用 4 个反斜杠。

      【讨论】:

        猜你喜欢
        • 2012-06-01
        • 1970-01-01
        • 2011-09-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多