hive导入本地文件
需要导入的数据:
1|a|10
2|a|12
3|b|13
4|b|12
5|a|14
6|a|15
7|a|13
8|b|11
9|a|16
一、在hive中创建表
create table xjj_rownum(id string,
type string,
price string)
row format delimited fields terminated by '|' stored as textfile;
二、将本地文件上传至Hadoop文件管理系统
1.对本地文件的操纵:字符集(编码方式)转化为utf-8 环境更改为unix
2.确定分隔符和表定义的分隔符一致
3.mkdir xjj 创建临时目录 cd xjj 进入目录xjj 使用rz命令上传至本地目录
4.pwd 查看linux文件位置 show create table_name查看文件在Hadoop中的位置
5.hadoop fs -put linux文件位置 hdfs路径
hadoop fs -put /home/bdp/cztest/xjj/hh.txt /user/hive/warehouse/hive_miguc.db/xjj_rownum
上传文件成功
load data [local] inpath '' [overwrite] into table table_name
三、用row_rownum函数进行排序
select * from XJJ_rownum;
select t.id,t.type,t.price,
row_number()over(partition by t.type order by t.price desc) rmp
from XJJ_rownum t;
select t.ip,t.session_id,t.platform,t.imei,
row_number()over(partition by t.platform order by t.imei desc) rmp
from dwd_fs_pure_userplay_d t limit 5;
select t.ip,t.session_id,t.platform,t.imei,
row_number()over(partition by t.platform order by t.imei desc) rmp
from dwd_fs_pure_userplay_d t
where rownum <=5;
