create static partition in hive
时间: 2023-08-31 14:13:33 浏览: 43
To create a static partition in Hive, you can use the following steps:
1. Create an external table in Hive with the columns you want to partition on.
2. Add the partition columns to the table schema.
3. Load data into the table.
4. Use the ALTER TABLE statement to add partitions to the table.
Here is an example of creating a static partition on a table in Hive:
```
CREATE EXTERNAL TABLE my_table (
column1 STRING,
column2 INT
)
PARTITIONED BY (partition_col STRING)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
LOCATION '/path/to/my_table';
-- Load data into the table
LOAD DATA INPATH '/path/to/data'
OVERWRITE INTO TABLE my_table
PARTITION (partition_col='my_partition');
-- Add partitions to the table
ALTER TABLE my_table ADD PARTITION (partition_col='another_partition') LOCATION '/path/to/another_partition';
```
In this example, we create an external table called `my_table` with the columns `column1` and `column2`. We also add a partition column called `partition_col` to the table schema. We then load data into the table and add two partitions using the `ALTER TABLE` statement.