user3898179
user3898179

Reputation: 231

Hive: Regex for backslash

I need to query for all rows that have a backslash character in between. This is the query I wrote:

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

(Had to manually type asterisk. The query had the symbol itself)

It is returning the entire table whether or not column B has backslash.

'.\\.' returned no rows even though there are rows where B has a backslash character.

Sample B - Hi can check the details for you/

Upvotes: 0

Views: 5124

Answers (3)

Latasha Papalal
Latasha Papalal

Reputation: 19

This question well explained in this blogpost.

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

In short, the answer is:

Use 4 backslashes.

Upvotes: 1

swapnil
swapnil

Reputation: 11

select regexp_replace(datecolumn,'-','\\') as dt from tablename;

Upvotes: 1

0x0FFF
0x0FFF

Reputation: 5018

Here's the basic guide on writing regular expressions: http://tldp.org/LDP/Bash-Beginners-Guide/html/chap_04.html

If you need to check whether backslash is in the string, try "instr" function, it is much simpler tran regexp: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-StringFunctions

As of regexp, it should be simply this: '\\'

One more good resource for checking regexp validity online: http://regex101.com/

Upvotes: 0

Related Questions