简体   繁体   English

在Hive中选择数据时,如果外部表分区位置数据丢失,如何通过错误?

[英]In Hive how to through error if external table partition location data is missing while selecting data?

I have created table External table "test" with partitioned column date.我已经创建了带有分区列日期的表外部表"test"

due to the some errors while importing data to "test" .It is just created directory(partition directory ) but not loaded into data,data is missing.由于将数据导入"test"时出现一些错误。它只是创建目录(分区目录)但未加载到数据中,数据丢失。

while selecting the data from particular partition, it is not showing any error it is giving zero records .从特定分区中选择数据时, it is not showing any error it is giving zero records

but I want to to throw error if data is missing while selecting,is there any way we can handle in hive?但是如果选择时数据丢失,我想抛出错误,有什么方法可以在 hive 中处理?

You can make the load process to fail using a property for dynamic partitions in Hive that can control that behavior while writing.您可以使用 Hive 中的动态分区属性来使加载过程失败,该属性可以在写入时控制该行为。 According to the documentation here you can find根据此处的文档,您可以找到

hive.error.on.empty.partition

    Default Value: false
    Added In: Hive 0.7.0

Whether to throw an exception if dynamic partition insert generates empty results.

I don't see the equivalent on static partitions, so you may need to query that particular partition and see whether it's empty.我在 static 分区上看不到等效的分区,因此您可能需要查询该特定分区并查看它是否为空。 That can make the load process to fail (for instance) if number of rows is lower than 1如果行数低于 1,这可能会使加载过程失败(例如)

Another option while reading is using a Hive UDF called assert_true that you can find here .阅读时的另一个选择是使用名为assert_true的 Hive UDF,您可以在此处找到。 As you can see there it returns a void and the format is如您所见,它返回一个void,格式为

assert_true(boolean condition)


Throw an exception if 'condition' is not true, otherwise return null (as of Hive 0.8.0). For example, select assert_true (2<1).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM