Hive支持复杂数据类型,如数组(ARRAY)、结构体(STRUCT)和Map

CREATE TABLE example_table (id INT,name STRING,address STRUCT<street:STRING, city:STRING, state:STRING, zip:STRING>,hobbies ARRAY<STRING>,contact_info MAP<STRING, STRING>);INSERT INTO example_table (id, name, address, hobbies, contact_info)VALUES (1, 'John Doe', STRUCT('123 Main St', 'New York', 'NY', '10001'), ARRAY('reading', 'traveling'), MAP('email', '[email protected]', 'phone', '123-456-7890'));SELECT * FROM example_table;SELECT id, name, address.street, address.city, address.state, address.zip, hobbies[0], contact_info['email'], contact_info['phone']FROM example_table;SELECT COUNT(DISTINCT hobbies) as unique_hobbiesFROM example_table;CREATE TABLE table2 (id INT,age INT,hobbies ARRAY<STRING>);INSERT INTO table2 (id, age, hobbies)VALUES (2, 30, ARRAY('swimming', 'cycling'));SELECT t1.id, t1.name, t1.address, t2.age, t2.hobbiesFROM example_table t1JOIN table2 t2 ON t1.id = t2.id;这些示例展示了如何在Hive中创建表、插入数据、查询数据以及处理复杂数据类型。您可以根据实际需求调整这些示例以满足您的用例。