Hive-built-in-operators
提供:Dev Guides
Hive-組み込み演算子
この章では、Hiveの組み込み演算子について説明します。 Hiveには4種類の演算子があります。
- 関係演算子
- 算術演算子
- 論理演算子
- 複雑な演算子
関係演算子
これらの演算子は、2つのオペランドを比較するために使用されます。 次の表に、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. |
例
上記の表を使用して従業員の詳細を取得するために、次のクエリが実行されます。
クエリが正常に実行されると、次の応答が表示されます。
次のクエリを実行して、給与がRs 40000以上の従業員の詳細を取得します。
クエリが正常に実行されると、次の応答が表示されます。
算術演算子
これらの演算子は、オペランドに対するさまざまな一般的な算術演算をサポートしています。 それらはすべて数値型を返します。 次の表に、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 |
例
次のクエリは、20と30の2つの数値を追加します。
クエリが正常に実行されると、次の応答が表示されます。
論理演算子
演算子は論理式です。 それらはすべてTRUEまたは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 |
例
次のクエリは、部門がTPで給与がRs 40000を超える従業員の詳細を取得するために使用されます。
クエリが正常に実行されると、次の応答が表示されます。
複雑な演算子
これらの演算子は、複合型の要素にアクセスする式を提供します。
Operator | Operand | Description |
---|---|---|
A[n] | 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. |