我們kylin環(huán)境安裝成功之后,我們就可以在hive當(dāng)中創(chuàng)建數(shù)據(jù)庫以及數(shù)據(jù)庫表,然后通過kylin來實現(xiàn)數(shù)據(jù)的查詢
第一步:創(chuàng)建hive數(shù)據(jù)庫以及表并加載以下數(shù)據(jù)
<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><v:stroke joinstyle="miter"><v:formulas></v:formulas><v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></v:path></v:stroke></v:shapetype><v:shape id="_x0000_i1025" style="width:41.4pt; height:41.4pt" type="#_x0000_t75" o:ole=""><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image001.emz"></v:imagedata></v:shape><v:shape id="_x0000_i1026" style="width:40.8pt; height:41.4pt" type="#_x0000_t75" o:ole=""><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image002.emz"></v:imagedata></v:shape>
將以上兩份文件上傳到node03服務(wù)器的/kkb/install路徑下,然后執(zhí)行以下命令,創(chuàng)建hive數(shù)據(jù)庫以及數(shù)據(jù)庫表,并加載數(shù)據(jù)
cd /kkb/install/hive-1.1.0-cdh5.14.2/
bin/beeline
創(chuàng)建數(shù)據(jù)庫并使用該數(shù)據(jù)庫
create database kylin_hive;
use kylin_hive;
(1)創(chuàng)建部門表
create external table if not exists kylin_hive.dept(
deptno int,
dname string,
loc int )
row format delimited fields terminated by '\t';
(2)創(chuàng)建員工表
create external table if not exists kylin_hive.emp(
empno int,
ename string,
job string,
mgr int,
hiredate string,
sal double,
comm double,
deptno int)
row format delimited fields terminated by '\t';
(3)查看創(chuàng)建的表
jdbc:hive2://node03:10000> show tables;
OK
tab_name
dept
emp
(4)向外部表中導(dǎo)入數(shù)據(jù)導(dǎo)入數(shù)據(jù)
load data local inpath '/kkb/install/dept.txt' into table kylin_hive.dept;
load data local inpath '/kkb/install/emp.txt' into table kylin_hive.emp;
查詢結(jié)果
jdbc:hive2://node03:10000> select * from emp;
jdbc:hive2://node03:10000> select * from dept;
第二步:訪問kylin瀏覽器界面,并創(chuàng)建project
直接在瀏覽器界面訪問
http://node02:8066/kylin/login 并登錄kylin,用戶名 ADMIN,密碼KYLIN
點擊頁面 + 號,來創(chuàng)建工程
<v:shape id="圖片_x0020_32" style="width:437.4pt;height:187.8pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1049"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png"></v:imagedata></v:shape>
輸入工程名稱以及工程描述
<v:shape id="圖片_x0020_42" style="width:437.4pt;height:141.6pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1048"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png"></v:imagedata></v:shape>
為工程添加數(shù)據(jù)源
<v:shape id="圖片_x0020_43" style="width:437.4pt;height:168.6pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1047"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png"></v:imagedata></v:shape>
添加數(shù)據(jù)源表
<v:shape id="圖片_x0020_45" style="width:436.8pt;height:102pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1046"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png"></v:imagedata></v:shape>
第三步:為kylin添加models
1、回到models頁面
<v:shape id="圖片_x0020_47" style="width:437.4pt;height:190.8pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1045"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png"></v:imagedata></v:shape>
2、添加new models
<v:shape id="圖片_x0020_67" style="width:437.4pt;height:259.2pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1044"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image008.png"></v:imagedata></v:shape>
3、填寫model name之后,繼續(xù)下一步
<v:shape id="圖片_x0020_68" style="width:438pt;height:108pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1043"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image009.png"></v:imagedata></v:shape>
4、選擇事實表
這里就選擇emp作為事實表
<v:shape id="圖片_x0020_69" style="width:436.8pt;height:106.2pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1042"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image010.png"></v:imagedata></v:shape>
5、添加維度表
添加我們的DEPT作為維度表,并選擇我們的join方式,以及join連接字段
<v:shape id="圖片_x0020_71" style="width:433.2pt;height:107.4pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1041"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image011.png"></v:imagedata></v:shape>
<v:shape id="圖片_x0020_70" style="width:438pt;height:160.2pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1040"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image012.png"></v:imagedata></v:shape>
6、選擇聚合維度信息
<v:shape id="圖片_x0020_72" style="width:436.8pt;height:124.8pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1039"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image013.png"></v:imagedata></v:shape>
7、選擇度量信息
<v:shape id="圖片_x0020_73" style="width:436.8pt;height:124.8pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1038"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image014.png"></v:imagedata></v:shape>
8、添加分區(qū)信息及過濾條件之后“Save”
<v:shape id="圖片_x0020_74" style="width:437.4pt;height:186.6pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1037"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image015.png"></v:imagedata></v:shape>
第四步:通過kylin來構(gòu)建cube
前面我們已經(jīng)創(chuàng)建了project和我們的models,接下來我們就來構(gòu)建我們的cube
1、頁面添加,創(chuàng)建一個new cube
<v:shape id="圖片_x0020_75" style="width:438pt;height:175.8pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1036"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image016.png"></v:imagedata></v:shape>
2、選擇我們的model以及cube name
<v:shape id="圖片_x0020_76" style="width:436.8pt;height:147.6pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1035"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image017.png"></v:imagedata></v:shape>
3、添加我們的自定義維度
<v:shape id="圖片_x0020_77" style="width:437.4pt;height:96pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1034"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image018.png"></v:imagedata></v:shape>
<v:shape id="圖片_x0020_79" style="width:438pt;height:204pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1033"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image019.png"></v:imagedata></v:shape>
4、添加統(tǒng)計維度
<v:shape id="圖片_x0020_44" style="width:436.8pt;height:169.8pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1032"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image020.png"></v:imagedata></v:shape>
<v:shape id="圖片_x0020_78" style="width:437.4pt;height:214.8pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1031"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image021.png"></v:imagedata></v:shape>
5、設(shè)置多個分區(qū)cube合并信息
因為我們這里是全量統(tǒng)計,不涉及多個分區(qū)cube進行合并,所以不用設(shè)置歷史多個cube進行合并
<v:shape id="圖片_x0020_80" style="width:437.4pt;height:221.4pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1030"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image022.png"></v:imagedata></v:shape>
6、高級設(shè)置
高級設(shè)置我們這里暫時也不做任何設(shè)置,后續(xù)再單獨詳細(xì)講解
<v:shape id="圖片_x0020_81" style="width:376.8pt;height:655.2pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1029"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image023.png"></v:imagedata></v:shape>
7、額外的其他的配置屬性,這里也暫時不做配置
<v:shape id="圖片_x0020_82" style="width:438pt;height:153.6pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1028"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image024.png"></v:imagedata></v:shape>
8、完成,保存配置
<v:shape id="圖片_x0020_83" style="width:437.4pt;height:174.6pt; visibility:visible;mso-wrap-style:square" type="#_x0000_t75" o:spid="_x0000_i1027"><v:imagedata o:title="" src="file:///C:\Users\chenning\AppData\Local\Temp\msohtmlclip1\01\clip_image025.png"></v:imagedata></v:shape>