hive分析的小練習

2021-09-12 00:03:17 字數 3015 閱讀 4379

一、題目:**指標分析案例

1、需求:統計每天24小時每小時的pv和uv數

2、分析:

-》pv:count(url)

-》uv:count(distinct guid)

3、資料採集

#建庫create database example;

#建表(源表)

create table log_src(

id string,

url string,

referer string,

keyword string,

type string,

guid string,

pageid string,

moduleid string,

linkid string,

attachedinfo string,

sessionid string,

trackeru string,

trackertype string,

ip string,

trackersrc string,

cookie string,

ordercode string,

tracktime string,

enduserid string,

firstlink string,

sessionviewno string,

productid string,

curmerchantid string,

provinceid string,

cityid string,

fee string,

edmactivity string,

edmemail string,

edmjobid string,

ieversion string,

platform string,

internalkeyword string,

resultsum string,

currentpage string,

linkposition string,

buttonposition string

)row format delimited fields terminated by '\t';

#載入資料

load data local inpath '/opt/datas/2015082818' into table log_src;

4、資料清洗

#建立分割槽表

create table log_part(

id string,

url string,

guid string

)partitioned by(day string,hour string)

row format delimited fields terminated by '\t';

#向log_part表新增待分析指標的資料

insert into table log_part partition(day='28',hour='18')

select id,url,guid from log_clean where hour='18'; -- 由於原資料沒有 18 的小時字段,因此要對資料進行清洗

#建立log_clean清洗表

create table log_clean as select

id,url,

guid,

substring(tracktime,9,2) day,

substring(tracktime,12,2) hour

from log_src;

#再次向log_part表載入資料

insert into table log_part partition(day='28',hour='18')

select id,url,guid from log_clean where day='28' and hour='18';

5、資料分析

#需求:統計每天24小時每小時的pv和uv數

#sql

select day,hour,count(url) as pv,count(distinct guid) as uv from log_part group by day,hour;

#結果day hour pv uv

28 18 64972 23938

#工作中會把最終的計算指標放到乙個表裡

create table log_result as select

day,

hour,

count(url) as pv,

count(distinct guid) as uv

from log_part group by day,hour;

#使用sqoop工具把log_result表的資料匯出到mysql

bin/sqoop export \

--connect jdbc:mysql://ai7-server1:3306/sqoop_test \

--username root \

--password 123456 \

--table from_hive \

--export-dir '/user/hive/warehouse/example.db/log_result' \

--input-fields-terminated-by '\t'

6、資料展示

從mysql表載入資料即可

Hive小練習實現單詞統計

su l hadoop 輸入密碼 vi word.txt 新建乙個word.txt文件,作為我們的資料檔案 輸入一些詞彙,以 為分隔符 hello world hello terese hello myfriend hello everyone esc wq儲存退出 hive 回到hive命令列中 ...

資料分析的小練習

檢視原始碼 ok!直接上 1.使用了scrapy框架,這裡給出爬蟲的 管道檔案的 coding utf 8 import scrapy from bosszhipin.items import bosszhipinitem class bossspider scrapy.spider name bo...

hive小練習 通訊掉話率統計

要求 根據所給資料,統計掉話率前十的基站。資料格式如下 掉話率 掉話率,是移動通訊中的重要指標,也稱通話中斷率,是指在移動通訊的過程中,通訊意外中斷的機率。本例的計算方法 掉話率 掉話時長 通話總時長。資料格式 資料條數 976306條。大小 54.7mb。關鍵字段介紹 imei 基站編號 cell...