【问题标题】:Replacing PIPE (|) symbol in hive替换 hive 中的 PIPE (|) 符号
【发布时间】:2016-06-06 10:27:12
【问题描述】:

您好,我有一个包含竖线 (|) 符号的文本,我想用空格替换它。这是列描述中的文字

|TrueCricketLover|百万欧元$$!| PTI|摩羯座|没有 DM|#TeamIK|@shaneRWatson33 ❤ 嘭嘭嘭❤ 努力成为更好的人!

我试过这样的regexp_replace函数

regexp_replace(description,'|',' ')

这个命令返回这个值

| T r u e C r i c k e t L o v e r |百万欧元! | P T I | C a p r i c o r n |否 D M | # T e a m I K | @s h a n e R W a t s o n 3 3 ❤ B o o m B o o m ❤ S t r i v i n g t o b e a b e t e r h u m a n ! L o v e h i m w h o l e a s t D e s e r v e s I t , T h a t ' s i t ❤

它没有替换管道 (|) 符号。请帮忙。

【问题讨论】:

  • 尝试转义管道字符。例如:regexp_replace(description,'\|',' ')
  • 它正在返回这个值 | T r u e C r i c k e t L o v e r |百万欧元! | P T I | C a p r i c o r n |否 D M | # T e a m I K | @s h a n e R W a t s o n 3 3 ❤ B o o m B o o m ❤ S t r i v i n g t o b e a b e t t e r h u m a n ! L o v e h i m w h o l e a s t D e s e r v e s I t , T h a t ' s i t ❤
  • 好的。试试这个:regexp_replace(description,'\\|',' ')
  • translate(description, '|', ' ')
  • regexp_replace(description,'\\|',' ') 完美运行

标签: hadoop hive regexp-replace


【解决方案1】:

试试这个: select regexp_replace(description,'\\|',' ') from table;

【讨论】:

    【解决方案2】:

    由于管道字符是正则表达式中的 OR 运算符,因此必须进行转义。在 Java 风格的正则表达式中,必须使用两个转义字符,即反斜杠。

    【讨论】:

      【解决方案3】:

      试试这个在你的 regexp_replace 函数中添加 \

      insert overwrite table_name select regexp_replace(id,'\\|',' ') from table_name

      【讨论】:

        猜你喜欢
        • 2021-05-16
        • 2017-05-26
        • 2018-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-01-28
        • 2014-08-21
        • 2020-07-15
        相关资源
        最近更新 更多