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', 'john.doe@example.com', '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_hobbies
FROM 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.hobbies
FROM example_table t1
JOIN table2 t2 ON t1.id = t2.id;
這些示例展示了如何在Hive中創建表、插入數據、查詢數據以及處理復雜數據類型。您可以根據實際需求調整這些示例以滿足您的用例。