Hive常见问题记录
# 常用函数
- coalesce ( expression [ ,...n ] ) :返回其参数中第一个非空表达式
- row_number() over(partition by field order by field) : 每个分组内对行进行排序并编号
- split(str,exp) : 拆分字符串
- size(ary) :求数组长度
- concat_ws( Separator,field [ ,...n ]) :连接字符串的函数
- collect_list(field) :对某一列进行合并
- collect_set(field) :对某一列进行合并(去重)
- get_json_object(str,'$.field') :解析json字符串,获取对应key的value值
- date_add(timestamp, num) :时间计算,如添加固定天数
- date_format(timestamp|str,formatStr) :时间格式化
# SQL
- 创建表
create external table if not exists my.table_name (
name String COMMENT ' ',
path String COMMENT ' ',
title String COMMENT ' ',
icon String COMMENT ' ',
index int COMMENT ' ',
visible int COMMENT ' '
)
COMMENT ''
stored as orcfile
location '/warehouse/my.db/table_name';
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- 创建临时表
create external table my.table_name stored as orcfile location '/warehouse/my.db/table_name' as
select ...
1
2
2
- 创建临时视图
ss.sql(sql.format([args])).createOrReplaceTempView("table_name")
1
- 删除视图
ss.catalog.dropTempView("table_name")
1
- 分区表插入
insert overwrite table table_name partition(分区字段) ...
1
最后更新时间: 2024/04/29, 16:24:38