What is the method for creating a partitioned table in Hive?
To create a partitioned table, use the PARTITIONED BY keyword to specify the partition column and then create partitions by specifying the values of the partition column. Below is an example code for creating a partitioned table:
CREATE TABLE my_table (
column1 INT,
column2 STRING
)
PARTITIONED BY (partition_column STRING)
You can then use the ALTER TABLE statement to add partitions.
ALTER TABLE my_table ADD PARTITION (partition_column='value1');
ALTER TABLE my_table ADD PARTITION (partition_column='value2');
Data can also be inserted and specified partitions using the INSERT statement.
INSERT INTO my_table PARTITION (partition_column='value1') VALUES (1, 'data1');
INSERT INTO my_table PARTITION (partition_column='value2') VALUES (2, 'data2');