You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Apache Drill中查看Map数据类型的大小?

How to Get the Size of a Map-Type Field in Apache Drill

Got it, let's solve this issue. When your Hive array field cdrlist gets converted to a Map in Apache Drill, the size() or REPEATED_COUNT() functions don't work as expected—but there are straightforward workarounds using Drill's built-in functions:

  • Use MAP_KEYS() combined with ARRAY_LENGTH()
    The MAP_KEYS() function extracts all keys from your Map into an array, and ARRAY_LENGTH() gives you the length of that array (which equals the number of key-value pairs in the Map). Here's the query:

    SELECT ARRAY_LENGTH(MAP_KEYS(cdrlist)) AS map_size FROM somet_table;
    
  • Alternative: MAP_VALUES() + ARRAY_LENGTH()
    This works the same way, but extracts the values of the Map into an array instead. Since every key has a corresponding value, the length will be identical:

    SELECT ARRAY_LENGTH(MAP_VALUES(cdrlist)) AS map_size FROM somet_table;
    

Both methods will reliably return the total number of entries in your Map field. Even if your Map contains NULL values, MAP_VALUES() will retain them, so the length calculation stays accurate.

内容的提问来源于stack exchange,提问作者Srihari Karanth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:55:33