Spark SQL rlike to find all strings with trailing numbers -


while querying data frame have tried use rlike without success.

sample data:

column_a|column_b 1|abc xyz 2|123 abc xyz 3|abc 123 xyz 4|abc 123 5|xyz 123 

expected output:

column_a|column_b 4|abc 123 5|xyz 123 

i have tried:

select * table_1 column_b rlike '\d+$' (select * table_1 column_b rlike '/\d+$') 

output (no results):

column_a|column_b 

i've tried:

select * table_1 column_b rlike '\d*$' (select * table_1 column_b rlike '/\d*$') 

output (all rows):

column_a|column_b 1|abc xyz 2|123 abc xyz 3|abc 123 xyz 4|abc 123 5|xyz 123 

is regex incorrect? have tested using python , online tester , looks correct. or rlike support specific regex?

you'll need bit more escaping make work. in particular:

spark.sql("select 'abc 123' rlike '\\\\d+$'").show() 
+------------------+ |abc 123 rlike \d+$| +------------------+ |              true| +------------------+ 
spark.sql("select '123 abc xyz' rlike '\\\\d+$'").show() 
+----------------------+ |123 abc xyz rlike \d+$| +----------------------+ |                 false| +----------------------+ 

Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -