【问题标题】:How to get length of complex datatype column in hive如何在配置单元中获取复杂数据类型列的长度
【发布时间】:2017-05-17 23:41:26
【问题描述】:

我有一个 hive 表包含 arraymap 类型的列,我想过滤数组/映射列包含超过 N 个元素的记录,该怎么做?

DDL:

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

查询:

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

【问题讨论】:

    标签: hadoop hive apache-spark-sql


    【解决方案1】:
    select * from test where size(v1)>10 or size(v2)>10
    

    演示

    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 |
    +----+----+
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 2013-02-09
      相关资源
      最近更新 更多