您好,登錄后才能下訂單哦!
這篇文章主要講解了“Sqoop+Hive+MySQL怎么配置用戶某時間范圍”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Sqoop+Hive+MySQL怎么配置用戶某時間范圍”吧!
一、創建配置文件
【1、創建table_env文件,增加如下內容】
執行命令:vi table_env
內容:
此處)折疊或打開
insert overwrite directory '${hivevar:hdfs_path}' ROW FORMAT DELIMITED FIELDS TERMINATED BY '${hivevar:field_term}' select * from (select c.area,p.product_name,
sum(rn) visit_num,
row_number()over(partition by c.area order by sum(rn) desc) rn,
'${hivevar:action_time}' action_time
from city_info c join (
select product_id,city_id,count(1) rn from user_click where action_time='${hivevar:action_time}' group by product_id,city_id
) u join product_info p
on c.city_id = case when u.city_id is null then concat('cityid',rand()) else u.city_id end
and p.product_id = case when u.product_id is null then concat('prodid',rand()) else u.product_id end
group by c.area,p.product_name) a
where a.rn <= 3;
退出保存(:wq)
【3、創建從Hive導出腳本:創建hive_to_mysql.sh文件,增加如下內容】
執行命令:vi hive_to_mysql.sh
內容:
此處)折疊或打開
create database works DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
1.2、創建表
點擊(此處)折疊或打開
--城市表
create table city_info(
city_id int,
city_name varchar(255),
area varchar(255)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--產品表
create table product_info(
product_id int,
product_name varchar(50),
extend_info varchar(100)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 用戶點擊表
create table user_click(
user_id int,
session_id varchar(50),
action_time varchar(30),
city_id int(11),
product_id int(11)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
--統考結果表
create table user_click_rs(
area varchar(50),
product_name varchar(50),
visit_num int(11),
rn int(11),
sdate varchar(10)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
【2、Hive信息】
創建HIve表
點擊(此處)折疊或打開
--用戶點擊表
create external table user_click(
user_id string,
session_id string,
city_id string,
product_id string
)
partitioned by (action_time string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
location '/works/user_click';
--用戶點擊臨時表
create external table tmp_user_click(
user_id string,
session_id string,
action_time string,
city_id string,
product_id string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
location '/works/tmp_user_click';
--城市表
create external table city_info(
city_id int,
city_name string,
area string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
location '/works/city_info';
--產品表
create external table product_info(
product_id int,
product_name string,
extend_info string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
location '/works/product_info';
感謝各位的閱讀,以上就是“Sqoop+Hive+MySQL怎么配置用戶某時間范圍”的內容了,經過本文的學習后,相信大家對Sqoop+Hive+MySQL怎么配置用戶某時間范圍這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。