In my hive table, the session
field is a string in format like:
ip-sessionID-userID
or area-sessionID-userID
There's 3 or 4 fields separated by "-
", but userID is always the last one.
i wanna select userID, but how to access the last field? In python, there's something like:
arr[-1]
but in hive, how to achieve this? The following SQL seems not correct.
select split(session,"\-")[-1] as user from my_table;
Thanks!
reverse(split(reverse(session), '-')[0])
Although this might be a bit more expensive than the regex solution ;)