I would like to use hiveql UDF to check whether the string contains any specific character or not?
I came across the below one.
find_in_set(str, strlist)
Is this the correct UDF to use?
For example:
the below column contains "1" in the value.
column1 = "test1String"
i need to write a HiveQL where condition to return the rows with column1 value contains 1.
int instr(string str, string substr)
Returns the position of the first occurrence of substr in str. Returns null if either of the arguments are null and returns 0 if substr could not be found in str. Be aware that this is not zero based. The first character in str has index 1.
select case when instr (column1, '1') >0 then 'contains' else 'not contains' end from ...
See this for reference: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF
Also using rlike
:
select case when column1 rlike '1' then 'contains' else 'not contains' end
Using like
:
select case when column1 like '%1%' then 'contains' else 'not contains' end
Using locate
:
select case when locate('1', column1) >0 then 'contains' else 'not contains' end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With