0
votes

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?

1

1 Answers

0
votes

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