Hive SQL 常用函数
Hive SQL 提供了丰富的内置函数,用于处理和分析数据。以下是一些常用的 Hive SQL 函数:
字符串函数:
length(string A):返回字符串 A 的长度。reverse(string A):反转字符串 A。concat(string A, string B, ...):连接字符串 A、B 等。substring(string A, int start, int len):返回字符串 A 从 start 位置开始,长度为 len 的子字符串。upper(string A):将字符串 A 转换为大写。lower(string A):将字符串 A 转换为小写。
日期函数:
year(string date):返回日期 date 的年份。month(string date):返回日期 date 的月份。day(string date):返回日期 date 的日期。date_add(string startdate, int days):将日期 startdate 增加 days 天。date_sub(string startdate, int days):将日期 startdate 减少 days 天。
聚合函数:
count(*):返回所有行的数量。count(DISTINCT col):返回 col 列中不同值的數量。sum(col):返回 col 列所有值的总和。avg(col):返回 col 列所有值的平均值。min(col):返回 col 列的最小值。max(col):返回 col 列的最大值。
其他函数:
coalesce(T v1, T v2, ...):返回第一个非空值。case when condition1 then result1 when condition2 then result2 else resultN end:根据条件返回值。