Hive - Built-in Operators
2017-01-20 17:36
267 查看
This chapter explains the built-in operators of Hive. There are four types of operators in Hive:
Relational Operators:关系操作
Arithmetic Operators
Logical Operators
Complex Operators:比较复杂的是这个,目前博主还没有实际玩过这个,在hue中体验了一把,还是挺好玩的。http://demo.gethue.com
The following query is executed to retrieve the employee details using the above table:
On successful execution of query, you get to see the following response:
The following query is executed to retrieve the employee details whose salary is more than or equal to Rs 40000.
On successful execution of query, you get to see the following response:
On successful execution of the query, you get to see the following response:
On successful execution of the query, you get to see the following response:
译注:这块本人还没有实际玩过,就找一个demo:http://demo.gethue.com/
--- 其实HUE还是很智能的,提示很给力!
-----------
英文地址:https://www.tutorialspoint.com/hive/hive_built_in_operators.htm
Relational Operators:关系操作
Arithmetic Operators
Logical Operators
Complex Operators:比较复杂的是这个,目前博主还没有实际玩过这个,在hue中体验了一把,还是挺好玩的。http://demo.gethue.com
Relational Operators
These operators are used to compare two operands. The following table describes the relational operators available in Hive:Operator | Operand | Description |
---|---|---|
A = B | all primitive types | TRUE if expression A is equivalent to expression B otherwise FALSE. |
A != B | all primitive types | TRUE if expression A is not equivalent to expression B otherwise FALSE. |
A < B | all primitive types | TRUE if expression A is less than expression B otherwise FALSE. |
A <= B | all primitive types | TRUE if expression A is less than or equal to expression B otherwise FALSE. |
A > B | all primitive types | TRUE if expression A is greater than expression B otherwise FALSE. |
A >= B | all primitive types | TRUE if expression A is greater than or equal to expression B otherwise FALSE. |
A IS NULL | all types | TRUE if expression A evaluates to NULL otherwise FALSE. |
A IS NOT NULL | all types | FALSE if expression A evaluates to NULL otherwise TRUE. |
A LIKE B | Strings | TRUE if string pattern A matches to B otherwise FALSE. |
A RLIKE B | Strings | NULL if A or B is NULL, TRUE if any substring of A matches the Java regular expression B , otherwise FALSE. |
A REGEXP B | Strings | Same as RLIKE. |
Example
Let us assume the employee table is composed of fields named Id, Name, Salary, Designation, and Dept as shown below. Generate a query to retrieve the employee details whose Id is 1205.+-----+--------------+--------+---------------------------+------+ | Id | Name | Salary | Designation | Dept | +-----+--------------+------------------------------------+------+ |1201 | Gopal | 45000 | Technical manager | TP | |1202 | Manisha | 45000 | Proofreader | PR | |1203 | Masthanvali | 40000 | Technical writer | TP | |1204 | Krian | 40000 | Hr Admin | HR | |1205 | Kranthi | 30000 | Op Admin | Admin| +-----+--------------+--------+---------------------------+------+
The following query is executed to retrieve the employee details using the above table:
hive> SELECT * FROM employee WHERE Id=1205;
On successful execution of query, you get to see the following response:
+-----+-----------+-----------+----------------------------------+ | ID | Name | Salary | Designation | Dept | +-----+---------------+-------+----------------------------------+ |1205 | Kranthi | 30000 | Op Admin | Admin | +-----+-----------+-----------+----------------------------------+
The following query is executed to retrieve the employee details whose salary is more than or equal to Rs 40000.
hive> SELECT * FROM employee WHERE Salary>=40000;
On successful execution of query, you get to see the following response:
+-----+------------+--------+----------------------------+------+ | ID | Name | Salary | Designation | Dept | +-----+------------+--------+----------------------------+------+ |1201 | Gopal | 45000 | Technical manager | TP | |1202 | Manisha | 45000 | Proofreader | PR | |1203 | Masthanvali| 40000 | Technical writer | TP | |1204 | Krian | 40000 | Hr Admin | HR | +-----+------------+--------+----------------------------+------+
Arithmetic Operators
These operators support various common arithmetic operations on the operands. All of them return number types. The following table describes the arithmetic operators available in Hive:Operators | Operand | Description |
---|---|---|
A + B | all number types | Gives the result of adding A and B. |
A - B | all number types | Gives the result of subtracting B from A. |
A * B | all number types | Gives the result of multiplying A and B. |
A / B | all number types | Gives the result of dividing B from A. |
A % B | all number types | Gives the reminder resulting from dividing A by B. |
A & B | all number types | Gives the result of bitwise AND of A and B. |
A | B | all number types | Gives the result of bitwise OR of A and B. |
A ^ B | all number types | Gives the result of bitwise XOR of A and B. |
~A | all number types | Gives the result of bitwise NOT of A. |
Example
The following query adds two numbers, 20 and 30.hive> SELECT 20+30 ADD FROM temp;
On successful execution of the query, you get to see the following response:
+--------+ | ADD | +--------+ | 50 | +--------+
Logical Operators
The operators are logical expressions. All of them return either TRUE or FALSE.Operators | Operands | Description |
---|---|---|
A AND B | boolean | TRUE if both A and B are TRUE, otherwise FALSE. |
A && B | boolean | Same as A AND B. |
A OR B | boolean | TRUE if either A or B or both are TRUE, otherwise FALSE. |
A || B | boolean | Same as A OR B. |
NOT A | boolean | TRUE if A is FALSE, otherwise FALSE. |
!A | boolean | Same as NOT A. |
Example
The following query is used to retrieve employee details whose Department is TP and Salary is more than Rs 40000.hive> SELECT * FROM employee WHERE Salary>40000 && Dept=TP;
On successful execution of the query, you get to see the following response:
+------+--------------+-------------+-------------------+--------+ | ID | Name | Salary | Designation | Dept | +------+--------------+-------------+-------------------+--------+ |1201 | Gopal | 45000 | Technical manager | TP | +------+--------------+-------------+-------------------+--------+
Complex Operators
These operators provide an expression to access the elements of Complex Types.Operator | Operand | Description |
---|---|---|
A | A is an Array and n is an int | It returns the nth element in the array A. The first element has index 0. |
M[key] | M is a Map<K, V> and key has type K | It returns the value corresponding to the key in the map. |
S.x | S is a struct | It returns the x field of S. |
-- 查询中包含了Map,Struct类型的两个字段查询 select addresses["shipping"],email_preferences.email_format from customers ;
--- 其实HUE还是很智能的,提示很给力!
-----------
英文地址:https://www.tutorialspoint.com/hive/hive_built_in_operators.htm
相关文章推荐
- C++ Built-in Operators, Precedence and Associativity
- [Hive - Tutorial] Built In Operators and Functions 内置操作符与内置函数
- Oracle Built-in Operators
- Missing Hive Builtins Jar: /data/hive-0.11.0/lib/hive-builtins-*.jar
- (转)使用Hive UDF和GeoIP库为Hive加入IP识别功能
- Hive--行转列(Lateral View explode())和列转行(collect_set() 去重)
- hive计算inner join报内存溢出
- 关于hive异常:Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStor
- Built-in custom editor styles in Unity3D
- Hive中的数据类型和文件格式
- str_to_map hive 字符串转为map格式
- hive表信息查询:查看表结构、表操作等
- hive常用命令
- hive学习之一:认识hive
- 通过 Spark R 操作 Hive
- Hive的日期函数
- hive基本操作
- kettle 5.1.0 连接 Hadoop hive 2 (hive 1.2.1)
- Hive 内建操作符与函数开发——深入浅出学Hive
- Hive2.0函数大全