因工作需要柿汛,要將hue上的數(shù)據(jù)導出到mysql,方便做展示埠对。但是存儲人手不足络断,只好自己上了裁替。
大致流程是,在hue上建一個工作流即可貌笨,下面講一下詳細的步驟弱判。
Step 1: 建 Workflow
- 點擊[Workflows]->[Editors]->[Workflows]
- 點擊[Create]
- 添加[Hive Script]
example_hive_script.sql
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
create table if not exists dst.test_table
(a bigint, b bigint) partitioned by (day string);
insert overwrite table dst.test_table partition(day="${day}")
SELECT a,
max(b),
FROM src.test_table
WHERE DAY="${day}"
GROUP BY a
ORDER BY a
- 添加[Sqoop command]
example Sqoop command
export --connect jdbc:mysql://ip:port/test_db --username name --password passwd --table test_table --fields-terminated-by '\t' --update-key a --update-mode allowinsert --export-dir /path/dst/test_table/day=${day}
Step 2: 建 mysql 數(shù)據(jù)表
- 連接到數(shù)據(jù)庫
mysql -u name -p -h ip -P port test_db
- 創(chuàng)建新表
mysql> create table if not exists test_table(
a bigint,
b bigint,
primary key(a)
);
note: mysql表要和hive的字段一致
Step 3: 建 Coordinator
直接[Create],指定Workflow锥惋,指定運行時間即可昌腰。
最后點擊[Submit]。
總結
學習了一番sql簡單的語句净刮,感覺收獲不少剥哑。