[
https://issues.apache.org/jira/browse/HIVE-9430?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14297794#comment-14297794
]
Sergio Peña commented on HIVE-9430:
-----------------------------------
Hi [~dlade]
There is no option to add a partition column to an existing table because the
table might have data that is already partitioned, and altering an existing
table would require to re-partition the data, and create/move files between
partition directories.
One way you can do it is by using dynamic partitions. Just create a table with
the partition scheme, then insert data to the partitioned table from the table
with no partitions. It will take a while because it is reading/writing data
from one table to another (not moving), but it is a way if you need to
partition your table.
Here's an example:
{noformat}
CREATE TABLE no_partitions (key string, value string);
.... // here you load data to your no_partitions table
-- This will add all rows with 'val_1' to a partition
CREATE TABLE with_partitions (key string) PARTITIONED BY (value string);
INSERT OVERWRITE TABLE with_partitions PARTITION (value = 'val_1') SELECT key
FROM no_partitions WHERE value like 'val_1';
-- Here you can add multiple partitions at once
FROM no_partitions
INSERT OVERWRITE TABLE with_partitions PARTITION (value = 'val_1') SELECT key
WHERE value like 'val_1'
INSERT OVERWRITE TABLE with_partitions PARTITION (value = 'val_2') SELECT key
WHERE value like 'val_2';
{noformat}
> NullPointerException on ALTER TABLE ADD PARTITION if no value given
> -------------------------------------------------------------------
>
> Key: HIVE-9430
> URL: https://issues.apache.org/jira/browse/HIVE-9430
> Project: Hive
> Issue Type: Bug
> Components: Query Processor
> Affects Versions: 0.13.0
> Reporter: Danny Lade
> Assignee: Sergio Peña
> Attachments: HIVE-9430.1.patch
>
>
> ALTER TABLE xxx ADD PARTITION (yyy) results in NullPointerException:
> {code:java}
> 2015-01-21 10:31:12,636 ERROR [main]: ql.Driver
> (SessionState.java:printError(545)) - FAILED: NullPointerException null
> java.lang.NullPointerException
> at
> org.apache.hadoop.hive.ql.parse.DDLSemanticAnalyzer.validatePartitionValues(DDLSemanticAnalyzer.java:2999)
> at
> org.apache.hadoop.hive.ql.parse.DDLSemanticAnalyzer.analyzeAlterTableAddParts(DDLSemanticAnalyzer.java:2680)
> at
> org.apache.hadoop.hive.ql.parse.DDLSemanticAnalyzer.analyzeInternal(DDLSemanticAnalyzer.java:393)
> at
> org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:327)
> at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:422)
> at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:322)
> at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:975)
> at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1040)
> at org.apache.hadoop.hive.ql.Driver.run(Driver.java:911)
> at org.apache.hadoop.hive.ql.Driver.run(Driver.java:901)
> at
> org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:268)
> at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:220)
> at
> org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:423)
> at
> org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:792)
> at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:686)
> at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:625)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:606)
> at org.apache.hadoop.util.RunJar.main(RunJar.java:212)
> {code}
> Therefore there is currently no way to add a partition to an already existing
> table.:
> {code:SQL}
> alter table XXX add partition (YYY = 'VALUE');
> FAILED: SemanticException table is not partitioned but partition spec exists:
> {YYY=VALUE}
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)