HiveQL - String contains equivalent in hiveql UDF?

11,385
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
Share:
11,385

Related videos on Youtube

Shankar
Author by

Shankar

Love Open Source and Big Data Technologies.

Updated on September 15, 2022

Comments

  • Shankar
    Shankar over 1 year

    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.

    • sumitya
      sumitya almost 8 years
      You already has an answer in last your last question's answer, @Gordon Linoff one. where column1 rlike '[1]'