Conditional Statements in Apache Hive

The use of conditional statements is very frequent when it comes to data interpretation. Often data manipulation, too, relies on conditional statements. Operators such as equal (=), greater than (>), less than (<) or a combination of any two operators shall produce a TRUE or FALSE value based on whether the comparison between the operands holds.

The below are examples of the conditional statements in Apache Hive.

Considering the popular “emp” dataset.

SELECT empno, sal, comm, sal=comm from emp;
The condition sal=comm returns true or false. If salary value is equal to commission value then it the result will be true. Else, false.

SELECT empno, sal, comm, sal<comm+1000 from emp;
Adding 1000 to the commission values and comparing it with Salary value. If salary value is less than to commission then it the result will be true. Else, false.


SELECT empno, sal, comm, if(comm=0, 100, comm) from emp;
With this implementation, if commission value 0 then the value will be replaced with 100. If not 0, then it returns commission value.


Hope you like this post.

Please do click on the follow button to receive notifications on latest posts.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s