Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HiveQL - String contains equivalent in hiveql UDF?

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.

like image 323
Shankar Avatar asked Jul 01 '16 11:07

Shankar


1 Answers

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
like image 109
leftjoin Avatar answered Sep 19 '22 16:09

leftjoin