Search code examples
pythonpandashivehql

Check count of repeated digits or characters in Hive column


I have a column with numbers in hive. I want to have the count of those rows where digits are repeated and this can be a case for a column of characters also.

Eg-Example column

Output should be 6.

I tried using reverse function of hive but it also gives palindrome numbers. Sample code which i tried -

select sum(case when Number = reverse(Number) then 1 else 0 end) as counts
from table
where Number is not null

Solution

  • select count(distinct Number) as dist_numbers
    from table
    where trim(number) rlike ^0+$|^1+$|^2+$|^3+$|^4+$|^5+$|^6+$|^7+$|^8+$|^9+$;
    

    This is a temporary but cumbersome approach.