fanwu72
fanwu72

Reputation: 91

What will happen if a hive(0.13) SELECT and INSERT OVERWRITE are running at the same time

I would like to know what will happen if a hive SELECT and INSERT OVERWRITE is running at the same time. Please help me to understand what will hive query return in the below scenarios.

Run the query first, while the query is running, INSERT OVERWRITE the same table.

Run the INSERT OVERWRITE first, while overwriting, pull the data from the same table with SELECT.

Are we going to get the old data, new data, mixed data, nothing, or unpredictable data?

I am using MapR 4.0.1, Hive 0.13.

Best regards,

Ryan

Upvotes: 7

Views: 2617

Answers (1)

Remus Rusanu
Remus Rusanu

Reputation: 294287

Read Hive Locking:

For a non-partitioned table, the lock modes are pretty intuitive. When the table is being read, a S lock is acquired, whereas an X lock is acquired for all other operations (insert into the table, alter table of any kind etc.)

So SELECT and INSERT acquire incompatible locks so they can never run in parallel. One will acquire the lock first and the other will wait.

For partitioned tables things are a bit more complex as the locks acquire are hierarchical (S on table, S/X on partition). Read the link.

Upvotes: 5

Related Questions