1.分区表:
是Hive中的一种表类型,通过将表中的数据划分为多个子集(分区),每个分区对应表中的某个特定的列值,可以提高查询性能和管理数据的效率。分区表的每个分区存储在单独的目录中,分区的定义基于表中的一个或多个列。使用分区表的主要目的是减少查询扫描的数据量,从而提高查询效率。
分区过细可能导致生成大量的小文件,影响HDFS性能和MapReduce任务的效率。需要定期进行小文件合并操作。
CREATE TABLE customer_data (
customer_id STRING,
name STRING,
age INT,
email STRING
)
PARTITIONED BY (city STRING)
STORED AS ORC;
select *
from customer_data;
-- 插入 New York 的数据
INSERT INTO TABLE customer_data PARTITION (city='New York')
VALUES
('1', 'John Doe', 30, 'john@example.com'),
('2', 'Jane Smith', 25, 'jane@example.com'),
('3', 'Bob Johnson', 40, 'bob@example.com');
-- 插入 Los Angeles 的数据
INSERT INTO TABLE customer_data PARTITION (city='Los Angeles')
VALUES
('4', 'Alice Brown', 32, 'alice@example.com'),
('5', 'Charlie Davis', 28, 'charlie@example.com');
-- 插入 Chicago 的数据
INSERT INTO TABLE customer_data PARTITION (city='Ch