简体   繁体   中英

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.

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.

while selecting the data from particular partition, 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?

You can make the load process to fail using a property for dynamic partitions in Hive that can control that behavior while writing. 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. That can make the load process to fail (for instance) if number of rows is lower than 1

Another option while reading is using a Hive UDF called assert_true that you can find here . As you can see there it returns a void and the format is

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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