1. 取整函数: round
语法: round(double a)
返回值: BIGINT
说明: 返回double类型的整数值部分 (遵循四舍五入)
举例:
1 | hive> select round(3.222511658) from student; |
2. 指定精度取整函数: round
语法: round(double a, int d)
返回值: DOUBLE
说明: 返回指定精度d的double类型,保留几位小数
举例:
1 | hive> select round(3.1415926,4) from student; |
3. 向下取整函数: floor
语法: floor(double a)
返回值: BIGINT
说明: 返回等于或者小于该double变量的最大的整数
举例:
1 | hive> select floor(3.1415926) from student; |
4. 向上取整函数: ceil
语法: ceil(double a)
返回值: BIGINT
说明: 返回等于或者大于该double变量的最小的整数
举例:
1 | hive> select ceil(3.1415926) from student; |
5. 向上取整函数: ceiling
语法: ceiling(double a)
返回值: BIGINT
说明: 与ceil功能相同
举例:
1 | hive> select ceiling(3.1415926) from student; |
6. 取随机数函数: rand
语法: rand(),rand(int seed)
返回值: double
说明: 返回一个0到1范围内的随机数。如果指定种子seed,则会得到一个稳定的随机数序列
举例:
1 | hive> select rand() from student; |
7. 自然指数函数: exp
语法: exp(double a)
返回值: double
说明: 返回自然对数e的a次方(2.718281828459045)
举例:
1 | hive> select exp(1) from student; |
8. 以10为底对数函数: log10
语法: log10(double a)
返回值: double
说明: 返回以10为底的a的对数
举例:
1 | hive> select log10(100) from student; |
9. 以2为底对数函数: log2
语法: log2(double a)
返回值: double
说明: 返回以2为底的a的对数
举例:
1 | hive> select log2(8) from student; |
10. 对数函数: log
语法: log(double base, double a)
返回值: double
说明: 返回以base为底的a的对数
举例:
1 | hive> select log(4,256) from student; |
11. 幂运算函数: pow
语法: pow(double a, double p)
返回值: double
说明: 返回a的p次幂
举例:
1 | hive> select pow(2,4) from student; |
12. 幂运算函数: power
语法: power(double a, double p)
返回值: double
说明: 返回a的p次幂,与pow功能相同
举例:
1 | hive> select power(2,4) from student; |
13. 开平方函数: sqrt
语法: sqrt(double a)
返回值: double
说明: 返回a的平方根
举例:
1 | hive> select sqrt(16) from student; |
14. 二进制函数: bin
语法: bin(BIGINT a)
返回值: string
说明: 返回a的二进制代码表示
举例:
1 | hive> select bin(7) from student; |
15. 十六进制函数: hex
语法: hex(BIGINT a)
返回值: string
说明: 如果变量是int类型,那么返回a的十六进制表示;如果变量是string类型,则返回该字符串的十六进制表示
举例:
1 | hive> select hex(17) from student; |
16. 反转十六进制函数: unhex
语法: unhex(string a)
返回值: string
说明: 返回该十六进制字符串所代码的字符串
举例:
1 | hive> select unhex(‘616263’) from student; |
17. 进制转换函数: conv
语法: conv(BIGINT num, int from_base, int to_base)
返回值: string
说明: 将数值num从from_base进制转化到to_base进制
举例:
1 | hive> select conv(17,10,16) from student; |
18. 绝对值函数: abs
语法: abs(double a) abs(int a)
返回值: double int
说明: 返回数值a的绝对值
举例:
1 | hive> select abs(-3.9) from student; |
19. 正取余函数: pmod
语法: pmod(int a, int b),pmod(double a, double b)
返回值: int double
说明: 返回正的a除以b的余数
举例:
1 | hive> select pmod(9,4) from student; |
20. 正弦函数: sin
语法: sin(double a)
返回值: double
说明: 返回a的正弦值
举例:
1 | hive> select sin(0.8) from student; |
21. 反正弦函数: asin
语法: asin(double a)
返回值: double
说明: 返回a的反正弦值
举例:
1 | hive> select asin(0.7173560908995228) from student; |
22. 余弦函数: cos
语法: cos(double a)
返回值: double
说明: 返回a的余弦值
举例:
1 | hive> select cos(0.9) from student; |
23. 反余弦函数: acos
语法: acos(double a)
返回值: double
说明: 返回a的反余弦值
举例:
1 | hive> select acos(0.6216099682706644) from student; |
24. positive函数: positive
语法: positive(int a), positive(double a)
返回值: int double
说明: 返回a
举例:
1 | hive> select positive(-10) from student; |
25. negative函数: negative
语法: negative(int a), negative(double a)
返回值: int double
说明: 返回-a
举例:
1 | hive> select negative(-5) from student; |