【问题标题】:Selecting data based on key in map column根据地图列中的键选择数据
【发布时间】:2021-07-06 09:36:12
【问题描述】:

我有一个复杂的数据类型作为列,它是一个带有嵌套数组的映射:map<int,array<int>>。数据如下所示:

| date       | id | info                      |
|------------|----|---------------------------|
| 2021-07-01 | 1  | {123:[a,b,c],111:[3,6,9]} |
| 2021-07-01 | 2  | null                      |
| 2021-07-01 | 3  | {123:[1,3]}               |
| 2021-07-01 | 4  | {40:[2]}                  |

如何根据 info 列的 key 进行过滤?例如,要返回所有以123 为键的行?我看到的文档似乎没有示例 - https://cwiki.apache.org/confluence/display/hive/languagemanual+types#LanguageManualTypes-ComplexTypes

预期的输出如下所示:

| date       | id | info                      |
|------------|----|---------------------------|
| 2021-07-01 | 1  | {123:[a,b,c],111:[3,6,9]} |
| 2021-07-01 | 3  | {123:[1,3]}               |

【问题讨论】:

    标签: sql dictionary hive hiveql


    【解决方案1】:

    只需过滤info[123] is not null:

    select * 
    from table
    where info[123] is not null
    

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      相关资源
      最近更新 更多