📅  最后修改于: 2020-12-03 03:51:34             🧑  作者: Mango
HiveQL运算符有助于执行各种算术和关系运算。在这里,我们将在下表的记录上执行此类操作:
让我们创建一个表,并使用以下步骤将数据加载到其中:-
hive> use hql;
hive> create table employee (Id int, Name string , Salary float)
row format delimited
fields terminated by ',' ;
hive> load data local inpath '/home/codegyani/hive/emp_data' into table employee;
hive> select * from employee;
现在,我们用相应的示例讨论算术和关系运算符。
在Hive中,算术运算运算符接受任何数字类型。常用的算术运算运算符为:-
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. |
hive> select id, name, salary + 50 from employee;
hive> select id, name, salary - 50 from employee;
hive> select id, name, (salary * 10) /100 from employee;
在Hive中,通常将关系运算符与诸如Join和Haven之类的子句一起使用以比较现有记录。常用的关系运算符是:-
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 | 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. |
hive> select * from employee where salary >= 25000;
hive> select * from employee where salary < 25000;