3
votes

I have a hive external table partitioned on dt(string).

Some values in partitioned column are none, which means that these rows go into the null partition(dt=HIVE_DEFAULT_PARTITION). I want to update location for this partition.

0: jdbc:hive2://localhost:10000/> alter table `zdb.table` partition(dt=__HIVE_DEFAULT_PARTITION__) set location "s3a://path/zdb.db/table/dt=__HIVE_DEFAULT_PARTITION__";
Error: Error while compiling statement: FAILED: ParseException line 1:71 missing \' at ')' near '<EOF>' (state=42000,code=40000)
0: jdbc:hive2://localhost:10000/> alter table `zdb.table` partition(dt=null) set location "s3a://path/zdb.db/table/dt=__HIVE_DEFAULT_PARTITION__";
Error: Error while compiling statement: FAILED: SemanticException [Error 10248]: Cannot add partition column dt of type void as it cannot be converted to type string (state=42000,code=10248)
0: jdbc:hive2://localhost:10000/> alter table `zdb.table` partition(dt="__HIVE_DEFAULT_PARTITION__") set location "s3a://path/zdb.db/table/dt=__HIVE_DEFAULT_PARTITION__";
Error: org.apache.hive.service.cli.HiveSQLException: Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. Unable to alter partition. Unable to alter partitions because table or database does not exist.
    at org.apache.hive.service.cli.operation.Operation.toSQLException(Operation.java:380)
    at org.apache.hive.service.cli.operation.SQLOperation.runQuery(SQLOperation.java:257)
    at org.apache.hive.service.cli.operation.SQLOperation.access$800(SQLOperation.java:91)
    at org.apache.hive.service.cli.operation.SQLOperation$BackgroundWork$1.run(SQLOperation.java:348)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1844)
    at org.apache.hive.service.cli.operation.SQLOperation$BackgroundWork.run(SQLOperation.java:363)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.hadoop.hive.ql.metadata.HiveException: Unable to alter partition. Unable to alter partitions because table or database does not exist.
    at org.apache.hadoop.hive.ql.metadata.Hive.alterPartitions(Hive.java:743)
    at org.apache.hadoop.hive.ql.exec.DDLTask.alterTable(DDLTask.java:3592)
    at org.apache.hadoop.hive.ql.exec.DDLTask.execute(DDLTask.java:390)
    at org.apache.hadoop.hive.ql.exec.Task.executeTask(Task.java:199)
    at org.apache.hadoop.hive.ql.exec.TaskRunner.runSequential(TaskRunner.java:100)
    at org.apache.hadoop.hive.ql.Driver.launchTask(Driver.java:2183)
    at org.apache.hadoop.hive.ql.Driver.execute(Driver.java:1839)
    at org.apache.hadoop.hive.ql.Driver.runInternal(Driver.java:1526)
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1237)
    at org.apache.hadoop.hive.ql.Driver.run(Driver.java:1232)
    at org.apache.hive.service.cli.operation.SQLOperation.runQuery(SQLOperation.java:255)
    ... 11 more
Caused by: InvalidOperationException(message:Unable to alter partitions because table or database does not exist.)
    at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$alter_partitions_with_environment_context_result$alter_partitions_with_environment_context_resultStandardScheme.read(ThriftHiveMetastore.java)
    at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$alter_partitions_with_environment_context_result$alter_partitions_with_environment_context_resultStandardScheme.read(ThriftHiveMetastore.java)
    at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$alter_partitions_with_environment_context_result.read(ThriftHiveMetastore.java)
    at org.apache.thrift.TServiceClient.receiveBase(TServiceClient.java:86)
    at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.recv_alter_partitions_with_environment_context(ThriftHiveMetastore.java:2843)
    at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Client.alter_partitions_with_environment_context(ThriftHiveMetastore.java:2827)
    at org.apache.hadoop.hive.metastore.HiveMetaStoreClient.alter_partitions(HiveMetaStoreClient.java:1533)
    at sun.reflect.GeneratedMethodAccessor166.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.invoke(RetryingMetaStoreClient.java:173)
    at com.sun.proxy.$Proxy34.alter_partitions(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor166.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.hadoop.hive.metastore.HiveMetaStoreClient$SynchronizedHandler.invoke(HiveMetaStoreClient.java:2336)
    at com.sun.proxy.$Proxy34.alter_partitions(Unknown Source)
    at org.apache.hadoop.hive.ql.metadata.Hive.alterPartitions(Hive.java:739)
    ... 21 more (state=08S01,code=1)

Also, I noticed that drop partition is working

0: jdbc:hive2://localhost:10000/> alter table `zdb.table` drop partition(dt="__HIVE_DEFAULT_PARTITION__") ;
No rows affected (0.08 seconds)

Using the same syntax with add partition fails

0: jdbc:hive2://localhost:10000/> alter table `zdb.table` add partition(dt="__HIVE_DEFAULT_PARTITION__") location "s3a://path/zdb.db/table/dt=__HIVE_DEFAULT_PARTITION__";
Error: Error while compiling statement: FAILED: SemanticException [Error 10111]: Partition value contains a reserved substring (User value: __HIVE_DEFAULT_PARTITION__ Reserved substring: __HIVE_DEFAULT_PARTITION__) (state=42000,code=10111)

For my use-case, I cannot use msck repair table <table-name>. Please suggest if there is a work-around for this

1

1 Answers

3
votes

enclose __HIVE_DEFAULT_PARTITION__ in quotes("") then you are able to set the location for default partition.

alter table `zdb.table` partition(dt="__HIVE_DEFAULT_PARTITION__") set location "s3a://path/zdb.db/table/dt=__HIVE_DEFAULT_PARTITION__";

We can't add __HIVE_DEFAULT_PARTITION__(as this is an reserved key word in hive) to the hive table but we can solve this issue using workaround.

INSERT INTO zdb.table PARTITION(DT) SELECT * FROM (SELECT <all columns except dt>,CAST(NULL AS STRING) DT )T;

Now __HIVE_DEFAULT_PARTITION__ will be available then we can use alter set location to change the partition location.