hive rownum()


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;

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM