1. 程式人生 > >hive數據去重

hive數據去重

create 結構 技術 重復數據 處理 個數 數據庫 number esc

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;

技術分享圖片

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

技術分享圖片

hive數據去重