Create Hive Partitioned Table Guide
The method for creating a partitioned table in Hive is as follows:
- Create a regular table.
CREATE TABLE table_name (
column1 data_type,
column2 data_type,
...
);
- Modify the table
ALTER TABLE table_name ADD PARTITION (partition_column=value);
- Change the structure of the table
ALTER TABLE table_name ADD PARTITION (partition_column=value1);
ALTER TABLE table_name ADD PARTITION (partition_column=value2);
...
- Display partitions.
SHOW PARTITIONS table_name;
- When inserting data, you can specify the value of the partitioning field.
INSERT INTO table_name PARTITION (partition_column=value) VALUES (value1, value2, ...);
By following the above steps, you can create and use partitioned tables in Hive.