In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "the grammar and usage of numeric functions in hive". In daily operation, I believe that many people have doubts about the grammar and usage of numeric functions in hive. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the grammar and usage of numeric functions in hive". Next, please follow the editor to study!
1. Take the whole function: round
Syntax: round (double a)
Return value: BIGINT
Description: returns the integer value part of the double type (following rounding)
For example:
Hive > select round (3.1415926) from lxw_dual
three
Hive > select round (3.5) from lxw_dual
four
Hive > create table lxw_dual as select round (9542.158) fromlxw_dual
Hive > describe lxw_dual
_ c0 bigint
two。 Specified precision integer function: round
Syntax: round (double a, int d)
Return value: DOUBLE
Description: returns the double type of the specified precision d
For example:
Hive > select round (3.1415926) from lxw_dual
3.1416
3. Take the whole function down: floor
Syntax: floor (double a)
Return value: BIGINT
Description: returns the largest integer equal to or less than the double variable
For example:
Hive > select floor (3.1415926) from lxw_dual
three
Hive > select floor (25) from lxw_dual
twenty-five
4. Take the whole function up: ceil
Syntax: ceil (double a)
Return value: BIGINT
Description: returns the smallest integer equal to or greater than the double variable
For example:
Hive > select ceil (3.1415926) from lxw_dual
four
Hive > select ceil (46) from lxw_dual
forty-six
5. Take the whole function up: ceiling
Syntax: ceiling (double a)
Return value: BIGINT
Description: same function as ceil
For example:
Hive > select ceiling (3.1415926) from lxw_dual
four
Hive > select ceiling (46) from lxw_dual
forty-six
6. Take random number function: rand
Syntax: rand (), rand (int seed)
Return value: double
Description: returns a random number in the range of 0 to 1. If you specify a seed seed, you will wait for a stable sequence of random numbers
For example:
Hive > select rand () from lxw_dual
0.5577432776034763
Hive > select rand () from lxw_dual
0.6638336467363424
Hive > select rand (100) from lxw_dual
0.7220096548596434
Hive > select rand (100) from lxw_dual
0.7220096548596434
7. Natural exponential function: exp
Syntax: exp (double a)
Return value: double
Description: returns the a power of the natural logarithm e
For example:
Hive > select exp (2) from lxw_dual
7.38905609893065
Natural logarithmic function: ln
Syntax: ln (double a)
Return value: double
Description: returns the natural logarithm of a
For example:
Hive > select ln (7.38905609893065) from lxw_dual
2.0
8. Logarithmic function with base 10: log10
Syntax: log10 (double a)
Return value: double
Description: returns the logarithm of a with a base of 10
For example:
Hive > select log10 (100) from lxw_dual
2.0
9. Logarithmic function with base 2: log2
Syntax: log2 (double a)
Return value: double
Description: returns the logarithm of a with base 2
For example:
Hive > select log2 (8) from lxw_dual
3.0
10. Logarithmic function: log
Syntax: log (double base, double a)
Return value: double
Description: returns the logarithm of a with base as the base
For example:
Hive > select log (4256) from lxw_dual
4.0
11. Exponentiation function: pow
Syntax: pow (double a, double p)
Return value: double
Description: returns the p power of a
For example:
Hive > select pow (2pr 4) from lxw_dual
16.0
twelve。 Exponentiation function: power
Syntax: power (double a, double p)
Return value: double
Description: returns the p power of a, which has the same function as pow
For example:
Hive > select power (2pr 4) from lxw_dual
16.0
13. Square function: sqrt
Syntax: sqrt (double a)
Return value: double
Description: returns the square root of a
For example:
Hive > select sqrt (16) from lxw_dual
4.0
14. Binary function: bin
Syntax: bin (BIGINT a)
Return value: string
Description: returns the binary representation of a
For example:
Hive > select bin (7) from lxw_dual
one hundred and eleven
15. Hexadecimal function: hex
Syntax: hex (BIGINT a)
Return value: string
Description: returns the hexadecimal representation of an if the variable is of type int; if the variable is of type string, the hexadecimal representation of the string
For example:
Hive > select hex (17) from lxw_dual
eleven
Hive > select hex ('abc') from lxw_dual
616263
16. Reverse hexadecimal function: unhex
Syntax: unhex (string a)
Return value: string
Description: returns the string coded by the hexadecimal string
For example:
Hive > select unhex ('616263') from lxw_dual
Abc
Hive > select unhex ('11') from lxw_dual
-
Hive > select unhex (616263) from lxw_dual
Abc
17. Binary conversion function: conv
Syntax: conv (BIGINT num, int from_base, int to_base)
Return value: string
Description: convert the numeric num from from_base to to_base
For example:
Hive > select conv (17, 10, 16) from lxw_dual
eleven
Hive > select conv (170.10jue 2) from lxw_dual
10001
18. Absolute value function: abs
Syntax: abs (double a) abs (int a)
Return value: double int
Description: returns the absolute value of the value a
For example:
Hive > select abs (- 3.9) from lxw_dual
3.9
Hive > select abs (10.9) from lxw_dual
10.9
19. Positive remainder function: pmod
Syntax: pmod (int a, int b), pmod (double a, double b)
Return value: int double
Description: returns the remainder of positive a divided by b
For example:
Hive > select pmod (9. 4) from lxw_dual
one
Hive > select pmod (- 9pm 4) from lxw_dual
three
20. Sine function: sin
Syntax: sin (double a)
Return value: double
Description: returns the sine of a
For example:
Hive > select sin (0.8) from lxw_dual
0.7173560908995228
21. Arcsine function: asin
Syntax: asin (double a)
Return value: double
Description: returns the arcsine of a
For example:
Hive > select asin (0.7173560908995228) from lxw_dual
0.8
twenty-two。 CoSine function: cos
Syntax: cos (double a)
Return value: double
Description: returns the cosine of a
For example:
Hive > select cos (0.9) from lxw_dual
0.6216099682706644
23. Inverse cosine function: acos
Syntax: acos (double a)
Return value: double
Description: returns the inverse cosine of a
For example:
Hive > select acos (0.6216099682706644) from lxw_dual
0.9
24. Positive function: positive
Syntax: positive (int a), positive (double a)
Return value: int double
Description: return a
For example:
Hive > select positive (- 10) from lxw_dual
-10
Hive > select positive (12) from lxw_dual
twelve
25. Negative function: negative
Syntax: negative (int a), negative (double a)
Return value: int double
Description: return-a
For example:
Hive > select negative (- 5) from lxw_dual
five
Hive > select negative (8) from lxw_dual
At this point, the study of "the grammar and usage of numeric functions in hive" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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: 212
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.