文字匯入hive表中

2021-09-12 11:43:09 字數 3667 閱讀 2447

一.確定資料檔案集合

1.**渠道

自行寫網路爬蟲採集:研發成本高、不是本職工作

公開資料集:無研發成本,公開資料集質量高,資料量可大可小,按需獲取即可。

第三方資料買賣公司:無研發成本,需要付費才能獲取。

2.渠道選擇

基於專案需求,選擇公開資料集即可。

搜狗搜驗室-

多領域公開資料集-

國外的公開資料集-

自行積累的公共資料集-

3.確定資料集

確定資料量級:

1.總大小

2.總檔案個數或者說平均檔案大小

3.總記錄條數(單個檔案大小/單個檔案記錄數 wc -l = 總檔案大小/總記錄條數)

本專案為:

2023年自年初到年末的約2.2億條微博資料

共52周的資料,分成52個zip包

4.確定資料檔案格式

csv格式

5.確定資料結構

mid, 訊息的唯一id

retweeted_status_mid, **的原創微博的mid

uid, 微博主id

retweeted_uid, **的原創微博的uid

source, 終端

image,

text, 內容

geo, 地理位置

create_at, 建立時間

deleted_last_seen, 微博被刪除時間

permission_denied 當微博被刪除後,設定成"permission denied"

二.將源資料裝載到hive倉庫

1.zip原始資料批量解壓到指定目錄

ls input_zip_dir/*.zip | xargs -n1 unzip -o -d output_csv_dir

2.在hive中建立weibo_origin和weibo_product兩張同構表

create external table weibo_origin(

mid string,

retweeted_status_mid string,

uid string,

retweeted_uid string,

source string,

image string,

text string,

geo string,

created_at string,

deleted_last_seen string,

permission_denied string

)comment 『weibo content table』

partitioned by (week_seq string comment 『the week sequence』)

row format delimited fields terminated by 『,』 lines terminated by 『\n』

stored as textfile;

create table weibo_product(

mid string,

retweeted_status_mid string,

uid string,

retweeted_uid string,

source string,

image string,

text string,

geo string,

created_at string,

deleted_last_seen string,

permission_denied string

)comment 『weibo content table』

partitioned by (week_seq string comment 『the week sequence』)

row format delimited fields terminated by 『,』 lines terminated by 『\n』

stored as orcfile;

3.將解壓完的明文每週資料表,按周load到weibo_origin載入原始資料

vi load_to_weibo_origin.sh

#!/bin/sh

source …/env.sh

output_csv_dir=/home/gudepeng/wbxm1/deal/wbsj

db_name=gudepeng

table_name=weibo_origin

week_seq_list=ls $input_zip_dir/*.csv | xargs -n1 echo | cut -d . -f1

for week_seq in week_seq_list;do

$hive -e "

use dbn

ame;

load

data

loca

linp

ath′

db_name; load data local inpath '

dbn​am

e;lo

adda

talo

cali

npat

h′output_csv_dir/week_seq.csv』 overwrite into table tab

lena

mepa

rtit

ion(

week

seq=

′table_name partition(week_seq='

tablen

​ame

part

itio

n(we

eks​

eq=′

week_seq』);

"done

4.清選原始資料表weibo_origin,按周插入到weibo_product表中

vi load_to_weibo_product.sh

#!/bin/sh

source …/env.sh

week_seq=week1

db_name=gudepeng

from_table=weibo_origin

to_table=weibo_product

$hive -e "

use dbn

ame;

from

(sel

ect∗

from

′db_name; from (select * from '

dbn​am

e;fr

om(s

elec

t∗fr

om′from_table』 where week_seq=『wee

kseq

′)on

ewee

kins

erto

verw

rite

tabl

e′

week_seq')oneweek insert overwrite table '

weeks​

eq′)

onew

eeki

nser

tove

rwri

teta

ble′

to_table』 partition(week_seq) select * where mid!=『mid』

"

從文字檔案匯入資料到hive表中

從文字檔案匯入資料到hive表中 1.資料儲存為csv格式,不能帶標題行,以逗號分隔,用tr命令將逗號替換成hive預設的 001分隔 tr 001 home zengsiwei362 zhoulixin54520150730.csv home zengsiwei362 zhoulixin54520...

hive 表插入 匯入資料

1 覆蓋現有分割槽資料,如果沒有該指定分割槽,新建該分割槽,並且插入資料 insert overwrite table 庫名.表名 partition dt 2018 09 12 name tom select from 庫名.表名 where.2 向現有的分割槽插入資料 之前的資料不會被覆蓋 in...

hive 本地檔案匯入表

在hive中將本地檔案匯入 建立名為idata tmp.yanxue hivetest的表 create table idata tmp.yanxue hivetest num int name string row format delimited fields terminated by t 注...