您好,登錄后才能下訂單哦!
小編給大家分享一下GaussDW如何導(dǎo)入MRS-Hive數(shù)據(jù)源,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
已創(chuàng)建DWS集群,需確保MRS和DWS集群在同一個(gè)區(qū)域、可用區(qū)、同一VPC子網(wǎng)內(nèi),確保集群網(wǎng)絡(luò)互通。
本實(shí)踐預(yù)計(jì)時(shí)長:1小時(shí),基本流程如下:
1、創(chuàng)建MRS分析集群(選擇Hive、Spark、Tez組件)。
2、通過將本地txt數(shù)據(jù)文件上傳至OBS桶,再通過OBS桶導(dǎo)入Hive,并由txt存儲(chǔ)表導(dǎo)入ORC存儲(chǔ)表。
3、創(chuàng)建MRS數(shù)據(jù)源連接。
4、創(chuàng)建外部服務(wù)器。
5、創(chuàng)建外表。
6、通過外表導(dǎo)入DWS本地表。
1、登錄華為云控制臺(tái),選擇“EI企業(yè)智能 > MapReduce服務(wù)”,單擊“購買集群”,選擇“自定義購買”,填寫軟件配置參數(shù),單擊“下一步”。
2、填寫硬件配置參數(shù),單擊“下一步”。
3、填寫高級(jí)配置參數(shù)如下表,單擊“立即購買”,等待約15分鐘,集群創(chuàng)建成功。
1、本地PC新建一個(gè)product_info.txt,并拷貝以下數(shù)據(jù),保存到本地。
100,XHDK-A-1293-#fJ3,2017-09-01,A,2017 Autumn New Shirt Women,red,M,328,2017-09-04,715,good 205,KDKE-B-9947-#kL5,2017-09-01,A,2017 Autumn New Knitwear Women,pink,L,584,2017-09-05,406,very good! 300,JODL-X-1937-#pV7,2017-09-01,A,2017 autumn new T-shirt men,red,XL,1245,2017-09-03,502,Bad. 310,QQPX-R-3956-#aD8,2017-09-02,B,2017 autumn new jacket women,red,L,411,2017-09-05,436,It's really super nice 150,ABEF-C-1820-#mC6,2017-09-03,B,2017 Autumn New Jeans Women,blue,M,1223,2017-09-06,1200,The seller's packaging is exquisite 200,BCQP-E-2365-#qE4,2017-09-04,B,2017 autumn new casual pants men,black,L,997,2017-09-10,301,The clothes are of good quality. 250,EABE-D-1476-#oB1,2017-09-10,A,2017 autumn new dress women,black,S,841,2017-09-15,299,Follow the store for a long time. 108,CDXK-F-1527-#pL2,2017-09-11,A,2017 autumn new dress women,red,M,85,2017-09-14,22,It's really amazing to buy 450,MMCE-H-4728-#nP9,2017-09-11,A,2017 autumn new jacket women,white,M,114,2017-09-14,22,Open the package and the clothes have no odor 260,OCDA-G-2817-#bD3,2017-09-12,B,2017 autumn new woolen coat women,red,L,2004,2017-09-15,826,Very favorite clothes 980,ZKDS-J-5490-#cW4,2017-09-13,B,2017 Autumn New Women's Cotton Clothing,red,M,112,2017-09-16,219,The clothes are small 98,FKQB-I-2564-#dA5,2017-09-15,B,2017 autumn new shoes men,green,M,4345,2017-09-18,5473,The clothes are thick and it's better this winter. 150,DMQY-K-6579-#eS6,2017-09-21,A,2017 autumn new underwear men,yellow,37,2840,2017-09-25,5831,This price is very cost effective 200,GKLW-l-2897-#wQ7,2017-09-22,A,2017 Autumn New Jeans Men,blue,39,5879,2017-09-25,7200,The clothes are very comfortable to wear 300,HWEC-L-2531-#xP8,2017-09-23,A,2017 autumn new shoes women,brown,M,403,2017-09-26,607,good 100,IQPD-M-3214-#yQ1,2017-09-24,B,2017 Autumn New Wide Leg Pants Women,black,M,3045,2017-09-27,5021,very good. 350,LPEC-N-4572-#zX2,2017-09-25,B,2017 Autumn New Underwear Women,red,M,239,2017-09-28,407,The seller's service is very good 110,NQAB-O-3768-#sM3,2017-09-26,B,2017 autumn new underwear women,red,S,6089,2017-09-29,7021,The color is very good 210,HWNB-P-7879-#tN4,2017-09-27,B,2017 autumn new underwear women,red,L,3201,2017-09-30,4059,I like it very much and the quality is good. 230,JKHU-Q-8865-#uO5,2017-09-29,C,2017 Autumn New Clothes with Chiffon Shirt,black,M,2056,2017-10-02,3842,very good
2、登錄OBS控制臺(tái),單擊“創(chuàng)建桶”,填寫以下參數(shù),單擊“立即創(chuàng)建”。
3、等待桶創(chuàng)建好,單擊桶名稱,選擇“對(duì)象 > 上傳對(duì)象”,將product_info.txt上傳至OBS桶。
4、切換回MRS控制臺(tái),單擊創(chuàng)建好的MRS集群名稱,進(jìn)入“概覽”,單擊“IAM用戶同步”所在行的“單擊同步”,等待約5分鐘同步完成。
5、回到MRS集群頁面,單擊“節(jié)點(diǎn)管理”,單擊任意一臺(tái)master節(jié)點(diǎn),進(jìn)入該節(jié)點(diǎn)頁面,切換到“彈性公網(wǎng)IP”,單擊“綁定彈性公網(wǎng)IP”,勾選已有彈性IP并單擊“確定”,如果沒有,請創(chuàng)建。記錄此公網(wǎng)IP。
6、確認(rèn)主master節(jié)點(diǎn)。
使用SSH工具以root用戶登錄以上節(jié)點(diǎn),root密碼為Huawei_12345,切換到omm用戶。
su - omm
執(zhí)行以下命令查詢主master節(jié)點(diǎn),回顯信息中“HAActive”參數(shù)值為“active”的節(jié)點(diǎn)為主master節(jié)點(diǎn)。
sh ${BIGDATA_HOME}/om-0.0.1/sbin/status-oms.sh
7、使用root用戶登錄主master節(jié)點(diǎn),切換到omm用戶,并進(jìn)入Hive客戶端所在目錄。
su - omm
cd /opt/client
8、在Hive上創(chuàng)建存儲(chǔ)類型為TEXTFILE的表product_info。
在/opt/client路徑下,導(dǎo)入環(huán)境變量。
source bigdata_env
登錄Hive客戶端。
beeline
依次執(zhí)行以下SQL語句創(chuàng)建demo數(shù)據(jù)庫及表product_info。
CREATE DATABASE demo; USE demo; DROP TABLE product_info; CREATE TABLE product_info ( product_price int not null, product_id char(30) not null, product_time date , product_level char(10) , product_name varchar(200) , product_type1 varchar(20) , product_type2 char(10) , product_monthly_sales_cnt int , product_comment_time date , product_comment_num int , product_comment_content varchar(200) ) row format delimited fields terminated by ',' stored as TEXTFILE
9、將product_info.txt數(shù)據(jù)文件導(dǎo)入Hive。
切回到MRS集群,單擊“文件管理”,單擊“導(dǎo)入數(shù)據(jù)”。
OBS路徑:選擇上面創(chuàng)建好的OBS桶名,找到product_info.txt文件,單擊“是”。
HDFS路徑:選擇/user/hive/warehouse/demo.db/product_info/,單擊“是”。
單擊“確定”,等待導(dǎo)入成功,此時(shí)product_info的表數(shù)據(jù)已導(dǎo)入成功。
10、創(chuàng)建ORC表,并將數(shù)據(jù)導(dǎo)入ORC表。
執(zhí)行以下SQL語句創(chuàng)建ORC表。
DROP TABLE product_info_orc; CREATE TABLE product_info_orc ( product_price int not null, product_id char(30) not null, product_time date , product_level char(10) , product_name varchar(200) , product_type1 varchar(20) , product_type2 char(10) , product_monthly_sales_cnt int , product_comment_time date , product_comment_num int , product_comment_content varchar(200) ) row format delimited fields terminated by ',' stored as orc;
將product_info表的數(shù)據(jù)插入到Hive ORC表product_info_orc中。
insert into product_info_orc select * from product_info;
查詢ORC表數(shù)據(jù)導(dǎo)入成功。
select * from product_info_orc;
登錄DWS管理控制臺(tái),單擊已創(chuàng)建好的DWS集群,確保DWS集群與MRS在同一個(gè)區(qū)域、可用分區(qū),并且在同一VPC子網(wǎng)下。
切換到“MRS數(shù)據(jù)源”,單擊“創(chuàng)建MRS數(shù)據(jù)源連接”。
選擇前序步驟創(chuàng)建名為的“MRS01”數(shù)據(jù)源,用戶名:admin,密碼:Huawei@12345,單擊“確定”,創(chuàng)建成功。
(1)使用Data Studio連接已創(chuàng)建好的DWS集群。
(2)新建一個(gè)具有創(chuàng)建數(shù)據(jù)庫權(quán)限的用戶dbuser:
CREATE USER dbuser WITH CREATEDB PASSWORD "Bigdata@123";
(3)切換為新建的dbuser用戶:
SET ROLE dbuser PASSWORD "Bigdata@123";
(4)創(chuàng)建新的mydatabase數(shù)據(jù)庫:
CREATE DATABASE mydatabase;
(5)執(zhí)行以下步驟切換為連接新建的mydatabase數(shù)據(jù)庫。
在Data Studio客戶端的“對(duì)象瀏覽器”窗口,右鍵單擊數(shù)據(jù)庫連接名稱,在彈出菜單中單擊“刷新”,刷新后就可以看到新建的數(shù)據(jù)庫。
右鍵單擊“mydatabase”數(shù)據(jù)庫名稱,在彈出菜單中單擊“打開連接”。
右鍵單擊“mydatabase”數(shù)據(jù)庫名稱,在彈出菜單中單擊“打開新的終端”,即可打開連接到指定數(shù)據(jù)庫的SQL命令窗口,后面的步驟,請全部在該命令窗口中執(zhí)行。
(6)為dbuser用戶授予創(chuàng)建外部服務(wù)器的權(quán)限:
GRANT ALL ON FOREIGN DATA WRAPPER hdfs_fdw TO dbuser;
其中FOREIGN DATA WRAPPER的名字只能是hdfs_fdw,dbuser為創(chuàng)建SERVER的用戶名。
(7)執(zhí)行以下命令賦予用戶使用外表的權(quán)限。
ALTER USER dbuser USEFT;
(8)切換回Postgres系統(tǒng)數(shù)據(jù)庫,查詢創(chuàng)建MRS數(shù)據(jù)源后系統(tǒng)自動(dòng)創(chuàng)建的外部服務(wù)器。
SELECT * FROM pg_foreign_server;
返回結(jié)果如:
srvname | srvowner | srvfdw | srvtype | srvversion | srvacl | srvoptions --------------------------------------------------+----------+--------+---------+------------+--------+--------------------------------------------------------------------------------------------------------------------- gsmpp_server | 10 | 13673 | | | | gsmpp_errorinfo_server | 10 | 13678 | | | | hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca | 16476 | 13685 | | | | {"address=192.168.1.245:9820,192.168.1.218:9820",hdfscfgpath=/MRS/8f79ada0-d998-4026-9020-80d6de2692ca,type=hdfs} (3 rows)
(9)切換到mydatabase數(shù)據(jù)庫,并切換到dbuser用戶。
SET ROLE dbuser PASSWORD "Bigdata@123";
(10)創(chuàng)建外部服務(wù)器。
SERVER名字、地址、配置路徑保持與8一致即可。
CREATE SERVER hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca FOREIGN DATA WRAPPER HDFS_FDW OPTIONS ( address '192.168.1.245:9820,192.168.1.218:9820', //MRS管理面的Master主備節(jié)點(diǎn)的內(nèi)網(wǎng)IP,可與DWS通訊。 hdfscfgpath '/MRS/8f79ada0-d998-4026-9020-80d6de2692ca', type 'hdfs' );
(11)查看外部服務(wù)器。
SELECT * FROM pg_foreign_server WHERE srvname='hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca';
返回結(jié)果如下所示,表示已經(jīng)創(chuàng)建成功:
srvname | srvowner | srvfdw | srvtype | srvversion | srvacl | srvoptions --------------------------------------------------+----------+--------+---------+------------+--------+--------------------------------------------------------------------------------------------------------------------- hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca | 16476 | 13685 | | | | {"address=192.168.1.245:9820,192.168.1.218:29820",hdfscfgpath=/MRS/8f79ada0-d998-4026-9020-80d6de2692ca,type=hdfs} (1 row)
1、獲取Hive的product_info_orc的文件路徑。
登錄MRS管理控制臺(tái)。
選擇“集群列表 > 現(xiàn)有集群”,單擊要查看的集群名稱,進(jìn)入集群基本信息頁面。
單擊“文件管理”,選擇“HDFS文件列表”。
進(jìn)入您要導(dǎo)入到GaussDB(DWS)集群的數(shù)據(jù)的存儲(chǔ)目錄,并記錄其路徑。
圖1 在MRS上查看數(shù)據(jù)存儲(chǔ)路徑
2、創(chuàng)建外表。 SERVER名字填寫10創(chuàng)建的外部服務(wù)器名稱,foldername填寫1查到的路徑。
DROP FOREIGN TABLE IF EXISTS foreign_product_info; CREATE FOREIGN TABLE foreign_product_info ( product_price integer not null, product_id char(30) not null, product_time date , product_level char(10) , product_name varchar(200) , product_type1 varchar(20) , product_type2 char(10) , product_monthly_sales_cnt integer , product_comment_time date , product_comment_num integer , product_comment_content varchar(200) ) SERVER hdfs_server_8f79ada0_d998_4026_9020_80d6de2692ca OPTIONS ( format 'orc', encoding 'utf8', foldername '/user/hive/warehouse/demo.db/product_info_orc/' ) DISTRIBUTE BY ROUNDROBIN;
1、創(chuàng)建本地目標(biāo)表。
DROP TABLE IF EXISTS product_info; CREATE TABLE product_info ( product_price integer not null, product_id char(30) not null, product_time date , product_level char(10) , product_name varchar(200) , product_type1 varchar(20) , product_type2 char(10) , product_monthly_sales_cnt integer , product_comment_time date , product_comment_num integer , product_comment_content varchar(200) ) with ( orientation = column, compression=middle ) DISTRIBUTE BY HASH (product_id);
2、從外表導(dǎo)入目標(biāo)表。
INSERT INTO product_info SELECT * FROM foreign_product_info;
3、查詢導(dǎo)入結(jié)果。
SELECT * FROM product_info;
以上是“GaussDW如何導(dǎo)入MRS-Hive數(shù)據(jù)源”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。