Labels

Tuesday, March 22, 2022

ACID Transactions in Hive (Class -12)

 Hive supports all ACID properties which enable us to use transactions, create transactional tables, and run queries like Insert, Update, and Delete on tables.

 ACID stands for four traits of database transactions:

A à Atomicity (an operation either succeeds completely or fails, it does not leave partial data)

C à Consistency (once an application performs an operation the results of that operation are visible to it in every subsequent operation),

I à Isolated (an incomplete operation by one user doesn’t cause unexpected side effects for other users)

D à Durability (once an operation is complete it will be preserved even in the face of machine or system failure).

Acid Properties can be done on Internal tables not External.



We can do DML (Insert, Delete & Update) operations in Hive if version is greater than > 0.13.

To perform DML Operations, Certain conditions need to be followed in ACID properties:

a)      Bucketed table

b)    b)   ORC
        c) Transaction Property has to be true

Create Hive table in bucketed format following ORC properties:   


hive> create table Hive_DML(EmployeeID Int,FirstName String,Designation String, Salary Int,Department String) clustered by (department) into 3 buckets stored as orc TBLPROPERTIES (‘transactional’=true’);

See above table is created in 3 Buckets form stored in ORC file format and transactional property is true.

 Now Insertion will allow but Update and Delete will not allow in table until properties have been set.


Below are the properties you need to enable ACID transactions.


a)      Now do the Insert operations,









 Now Update record in Hive:




Now Delete a file from Hive:




Go to Default path whether in Cloudera / Cloudxlab:



For every transaction, One Delta File will be created.


No comments:

Post a Comment