没有动态分区,无法向配置单元外部表添加/更新空分区

时间:2020-06-28 20:11:39

标签: hive hiveql

我在dt(string)上分区了一个配置单元外部表。

“分区”列中的某些值都不是,这意味着这些行将进入空分区(dt = HIVE_DEFAULT_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)

此外,我注意到拖放分区正在工作

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

添加分区使用相同的语法会失败

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)

对于我的用例,我不能使用msck repair table <table-name>。请建议是否有解决方法

1 个答案:

答案 0 :(得分:3)

__HIVE_DEFAULT_PARTITION__ 中封闭 quotes("") ,然后您可以设置默认分区的位置。

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

我们无法在配置单元表中添加 __HIVE_DEFAULT_PARTITION__ (因为这是配置单元中的保留关键字),但是我们可以使用解决方法来解决此问题。

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

现在__HIVE_DEFAULT_PARTITION__将可用,然后我们可以使用 alter set location 更改分区位置。

相关问题