如何在Apache Drill中查看Map数据类型的大小?
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 withARRAY_LENGTH()
TheMAP_KEYS()function extracts all keys from your Map into an array, andARRAY_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

