Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get length of complex datatype column in hive

I have a hive table contains columns of type array and map and I want to filter record where array/map column contains more than N elements, how to do that?

DDL:

create table test (id string, v1 array<int>, v2 map<string,string>)

Query:

select * from test where length(v1)>10 or length(v2)>10
like image 446
Rahul Sharma Avatar asked Feb 03 '26 15:02

Rahul Sharma


1 Answers

select * from test where size(v1)>10 or size(v2)>10

Demo

create table test (id string, v1 array<int>, v2 map<string,string>);
insert into test select 1,array(1,2,3,4,5),map('K1','V1','K2','V2','K3','V3');

select  size(v1),size(v2)
from    test
;

+----+----+
| c0 | c1 |
+----+----+
|  5 |  3 |
+----+----+
like image 126
David דודו Markovitz Avatar answered Feb 05 '26 09:02

David דודו Markovitz