I have hive table like below
create external table transaction(
id int,
name varchar(60))
month string
)
PARTITIONED BY (
year string,
transaction_type_code varchar(20)
)
STORED AS PARQUET
LOCATION 'hdfs://xyz';
I am creating one more external table with one more partition column dt like below
create external table transaction_copy(
id int,
name varchar(60))
month string
)
PARTITIONED BY (
dt string,
year string,
transaction_type_code varchar(20)
)
STORED AS PARQUET
LOCATION 'hdfs://xyz';
Adding partition like below
alter table transaction_copy add if not exists partition (dt='20210811') LOCATION 'hdfs://xyz';
Getting below exception
ERROR: Error while compiling statement: FAILED: ValidationFailureSemanticException partition spec {dt=20210810} doesn't contain all (3) partition columns
I am able to add partition by passing all 3 partitions .
Is it also possible by passing only one partition?
Not possible to add partition and specify only one column out of three because partitions in Hive are hierarchical, on hdfs partitions are hierarchical folders:
Each partition location path looks like this
hdfs://blabla-my-dwh/table_name/dt=1/year=1/transaction_type_code=1Data files normally are located in the leaf path folders, though, you can specify some custom location in hdfs which is not in this hierarchy, but the metadata for patition should contain all columns because without all columns it is not possible identify the partition at all.
BTW if
dtis a date andyearcan be derived from the samedt, then such partitioning makes no sense because each date will contain only one year inside.Also if you are creating external table with three partition columns, make sure you have data already organized in hierarchical folders, unless you are going to specify some custom location for each partition manually. CREATE EXTERNAL TABLE will not re-organize data for you, it will not work if there are no data folders for each partition.
If you have existing partitioned table and want to repartition using different partitioned schema, then you need to reload data: