二、HIVE 深入使用笔记

一、分区表
create table t_demo {
id string,
name string,
age int
}
partitioned by (year string,month string)
row format delimited fields terminated by '\t';

load data local inpath '/xxx/yyy/**.txt' into table t_demo partition(year='2018',month='02');
select * from t_demo where year='2018' and month='02'
注意事项:
  1. 如果对分区表,没有元数据,则可以通过msck repair table tablename修复,库中新增元数据
或者通过alter table add partition(year='2018',month='02'解决
  1. show partitions tablename;查看分区数 desc formatted tablename 查看表详情
二、导入数据
1.load data [local] inpath 'filepath' [overwrite] into table tablename [partition(prop1=xx,prop2=yy)]
  • 原始数据的存储位置 local 或 hdfs
  • 对标是否覆盖 overwrite或 追加
  • 分区
2.insert into target_table select * from source_table
3.用location加载,参考 hive 外表
三、命令导入导出数据
1.insert overwrite loca directory 'filepath' select * from tablename;
2.hive -e ' select * from tablename; ' > /opt/datas/demo.txt
3.import/export
四、排序及自定义函数
1.排序说明
  • order by :全局数据的排序,仅仅一个reduce
  • sort by :每个reduce内部进行排序
  • distribute by : 分区partition 经常跟sort by 配合使用,必须放sort by 前
  • cluster by : 即是distribute by 和 sort by 字段相同时等效
2.自定函数
UDF,UDAF,UDTF 分别是相当于普通函数(一对一),聚合函数(多对一),高级应用(一对多)
  • UDF继承UDF类,实现方法 ,add jar 添加或者create temporary function xx 'com.cn.xx'
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值