TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

HiveQL - Operators

HiveQL - Operators with tutorial, introduction, environment setup, first app hello world, state, props, flexbox, height and width, listview, scrollview, images, buttons, router, etc.

<< Back to HIVEQL

HiveQL - Operators

The HiveQL operators facilitate to perform various arithmetic and relational operations. Here, we are going to execute such type of operations on the records of the below table:

HiveQL - Operators

Example of Operators in Hive

Let's create a table and load the data into it by using the following steps: -

  • Select the database in which we want to create a table.
hive> use hql;  
  • Create a hive table using the following command: -
hive> create table employee (Id int, Name string , Salary float)  
row format delimited  
fields terminated by ',' ; 
  • Now, load the data into the table.
hive> load data local inpath '/home/codegyani/hive/emp_data' into table employee;
  • Let's fetch the loaded data by using the following command: -
hive> select * from employee;

HiveQL - Operators

Now, we discuss arithmetic and relational operators with the corresponding examples.

Arithmetic Operators in Hive

In Hive, the arithmetic operator accepts any numeric type. The commonly used arithmetic operators are: -

Operators Description
A + B This is used to add A and B.
A - B This is used to subtract B from A.
A * B This is used to multiply A and B.
A / B This is used to divide A and B and returns the quotient of the operands.
A % B This returns the remainder of A / B.
A | B This is used to determine the bitwise OR of A and B.
A & B This is used to determine the bitwise AND of A and B.
A ^ B This is used to determine the bitwise XOR of A and B.
~A This is used to determine the bitwise NOT of A.

Examples of Arithmetic Operator in Hive

  • Let's see an example to increase the salary of each employee by 50.
hive> select id, name, salary + 50 from employee;

HiveQL - Operators
  • Let's see an example to decrease the salary of each employee by 50.
hive> select id, name, salary - 50 from employee;  

HiveQL - Operators
  • Let's see an example to find out the 10% salary of each employee.
hive> select id, name, (salary * 10) /100 from employee;  

HiveQL - Operators

Relational Operators in Hive

In Hive, the relational operators are generally used with clauses like Join and Having to compare the existing records. The commonly used relational operators are: -

Operator Description
A=B It returns true if A equals B, otherwise false.
A <> B, A !=B It returns null if A or B is null; true if A is not equal to B, otherwise false.
A<B It returns null if A or B is null; true if A is less than B, otherwise false.
A>B It returns null if A or B is null; true if A is greater than B, otherwise false.
A<=B It returns null if A or B is null; true if A is less than or equal to B, otherwise false.
A>=B It returns null if A or B is null; true if A is greater than or equal to B, otherwise false.
A IS NULL It returns true if A evaluates to null, otherwise false.
A IS NOT NULL It returns false if A evaluates to null, otherwise true.

Examples of Relational Operator in Hive

  • Let's see an example to fetch the details of the employee having salary>=25000.
hive> select * from employee where salary >= 25000;

HiveQL - Operators
  • Let's see an example to fetch the details of the employee having salary<25000.
hive> select * from employee where salary < 25000;

HiveQL - Operators
Next TopicHiveQL - Functions




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf