Hive去除重復數據操作


 

Hive是基於Hadoop的一個數據倉庫工具,可以將結構化的數據文件映射為一張數據庫表,並提供類SQL查詢功能

hive的元數據存儲:通常是存儲在關系數據庫如 mysql(推薦) , derby(內嵌數據庫)中

hive的組成部分 :解釋器、編譯器、優化器、執行器

hive具有sql數據庫的外表,但應用場景完全不同,hive只適合用來做批量數據統計分析

hive中的數據表分為內部表、外部表

當刪除內部表的時候,表中的數據會跟着一塊刪除

刪除外部表時候,外部表會被刪除,外部表的數據不會被刪除

 

使用hive之前需要啟動hadoop集群,因為hive需要依賴於hadoop集群進行工作(hive2.0之前)

 

以下是對hive重復數據處理

先創建一張測試表

建表語句:create table hive_jdbc_test (key string,value string)   partitioned by (day string) row format delimited fields terminated by ','  stored as textfile

 

准備的數據
  uuid,hello=>0
  uuid,hello=>0
  uuid,hello=>1
  uuid,hello=>1
  uuid,hello=>2
  uuid,hello=>2
  uuid,hello=>3

 

把數據插入到2018-1-1分區

 

此時我們對hive表數據進行去重操作

insert overwrite table hive_jdbc_test partition(day='2018-1-1') 
select key,value 
from (SELECT *, Row_Number() OVER (partition by key,value ORDER BY value desc) rank 
FROM hive_jdbc_test where day='2018-1-1') t 
where t.rank=1;

 

此時重復數據會被處理完畢

 

 


免責聲明!

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



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