'Is there a "try" equivalent or work around in Hive?

I'm trying to pull an error code from a string, in Athena I can use:

split_part(text_column,'Error No.:',2) -- in order to get what is on the right of the error message

and

split_part(split_part(text_column,'Error No.:',2),',',1)

-- to get what is to the right of the "Error No." phrase and to the left of the comma

so: concat("Error No.:",split_part(split_part(text_column,'Error No.:',2),',',1)) gets me what I want in athena. Split part is not available in Hive.

So I tried:

concat('Error No.',split(split(text_column,'OTTOERR')[2],',')[1])

and I get the error

Array subscript out of bounds

But:

concat('Error No.',try(split(split(text_column,'OTTOERR')[2],',')[1]))

works. But you cannot use the "try" command in Hive. Does anyone know a workaround for this? Or how to just break down what try is doing so I could find one?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source