Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation of hive Mathematical Operation

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. Addition operation: +

Grammar: a + B

Operation types: all numeric types

Description: returns the result of the addition of An and B. The numeric type of the result is equal to the type of An and the smallest parent of the type of B. (see the inheritance relationship of the data type for details). For example, the general result of int + int is int, while the general result of int + double is double.

For example:

Hive > select1 + 9 from lxw_dual

ten

Hive > createtable lxw_dual as select 1 + 1.2 from lxw_dual

Hive > describe lxw_dual

_ c0 double

two。 Subtraction operation:-

Grammar: a-B

Operation types: all numeric types

Description: returns the result of subtracting An and B. The numeric type of the result is equal to the type of An and the smallest parent of the type of B. (see the inheritance relationship of the data type for details). For example, the general result of int-int is int, while the general result of int-double is double.

For example:

Hive > select10-5 from lxw_dual

five

Hive > createtable lxw_dual as select 5.6-4 from lxw_dual

Hive > describe lxw_dual

_ c0 double

3. Multiplication: *

Grammar: a * B

Operation types: all numeric types

Description: returns the result of multiplying An and B. The numeric type of the result is equal to the type of An and the smallest parent of the type of B. (see the inheritance relationship of the data type for details). Note that if the result of multiplying A by B exceeds the numerical range of the default result type, you need to convert the result to a wider range of numeric types through cast

For example:

Hive > select40 * 5 from lxw_dual

two hundred

4. Division operation: /

Grammar: a / B

Operation types: all numeric types

Description: returns the result of A divided by B. The numerical type of the result is double

For example:

Hive > select40 / 5 from lxw_dual

8.0

Note: the highest precision data type in hive is double, which is only accurate to 16 places after the decimal point. You should pay special attention when doing division operations.

Hive > select ceil (28.0 amp 6.999999999999999999999) from lxw_duallimit 1

The result is 4.

Hive > select ceil (28.0 amp 6.999999999999) from lxw_dual limit1

The result is 5.

5. Residual operation:%

Syntax: a% B

Operation types: all numeric types

Description: returns the remainder of A divided by B. The numeric type of the result is equal to the type of An and the smallest parent of the type of B. (see the inheritance relationship of the data type for details).

For example:

Hive > select 41 5 from lxw_dual

one

Hive > select 8.4 4 from lxw_dual

0.40000000000000036

Note: precision is a big problem in hive, and operations like this are best specified through round.

Hive > select round (8.4% 4,2) from lxw_dual

0.4

6. Bit and operation: &

Grammar: a & B

Operation types: all numeric types

Description: returns the results of bit-by-bit operations of An and B. The numeric type of the result is equal to the type of An and the smallest parent of the type of B. (see the inheritance relationship of the data type for details).

For example:

Hive > select 4 & 8 from lxw_dual

0

Hive > select 6 & 4 from lxw_dual

four

7. Bit or operation: |

Syntax: a | B

Operation types: all numeric types

Description: returns the result of bit-by-bit or operation of An and B. The numeric type of the result is equal to the type of An and the smallest parent of the type of B. (see the inheritance relationship of the data type for details).

For example:

Hive > select 4 | 8 from lxw_dual

twelve

Hive > select 6 | 8 from lxw_dual

fourteen

8. Bit XOR operation: ^

Grammar: a ^ B

Operation types: all numeric types

Description: returns the result of bit-by-bit XOR operations of An and B. The numeric type of the result is equal to the type of An and the smallest parent of the type of B. (see the inheritance relationship of the data type for details).

For example:

Hive > select 4 ^ 8 from lxw_dual

twelve

Hive > select 6 ^ 4 from lxw_dual

two

9. Bit inversion operation: ~

Syntax: ~ A

Operation types: all numeric types

Description: returns the result of A bitwise reverse operation. The numeric type of the result is equal to the type of A.

For example:

Hive > select ~ 6 from lxw_dual

-7

Hive > select ~ 4 from lxw_dual

-5

For more exciting content, please follow: http://bbs.superwu.cn

Follow the Superman College Wechat QR code:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report