1 创建工程

1)点击下图中的"+"。

kylin 配置连接hive Keytab验证 kylin和hive_hadoop

2)填写项目名称和描述信息,并点击Submit按钮提交。

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_02

 2 获取数据源

1)点击DataSource

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_03

2)点击下图按钮导入Hive表

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_04

3)选择以下表格,并点击Sync按钮

dwd_order_detail

dim_sku_info

dim_user_info

dim_base_province

kylin 配置连接hive Keytab验证 kylin和hive_字段_05

kylin 配置连接hive Keytab验证 kylin和hive_字段_06

注意事项

Kylin不能处理Hive表中的复杂数据类型(Array,Map,Struct),即便复杂类型的字段并未参与到计算之中。故在加载Hive数据源时,不能直接加载带有复杂数据类型字段的表。而在dim_sku_info表中存在两个复杂数据类型的字段(平台属性和销售属性),故dim_sku_info不能直接加载,需对其进行以下处理。

(1)在hive客户端创建一个视图,如下。该视图已经将dim_sku_info表中的复杂数据类型的字段去掉,在后续的计算中,不再使用dim_sku_info,而使用dim_sku_info_view。

先启动Hive

kylin 配置连接hive Keytab验证 kylin和hive_大数据_07

 hive (default)> use gmall;

hive (gmall)>
create view dim_sku_info_view
as
select
    id,
    price,
    sku_name,
    sku_desc,
    weight,
    is_sale,
    spu_id,
    spu_name,
    category3_id,
    category3_name,
    category2_id,
    category2_name,
    category1_id,
    category1_name,
    tm_id,
    tm_name,
    create_time
from dim_sku_info;

kylin 配置连接hive Keytab验证 kylin和hive_大数据_08

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_09

 (2)在kylin中重新导入dim_sku_info_view视图

kylin 配置连接hive Keytab验证 kylin和hive_kylin_10

 删除用不到的表

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_11

 3 创建model

1)点击Models,点击"+New"按钮,点击"★New Model"按钮。

kylin 配置连接hive Keytab验证 kylin和hive_字段_12

2)填写Model信息,点击Next

kylin 配置连接hive Keytab验证 kylin和hive_字段_13

3)指定事实表

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_14

4)选择维度表,并指定事实表和维度表的关联条件,点击Ok

 点击Add Lookup Table

kylin 配置连接hive Keytab验证 kylin和hive_大数据_15

kylin 配置连接hive Keytab验证 kylin和hive_大数据_16

kylin 配置连接hive Keytab验证 kylin和hive_kylin_17

维度表添加完毕之后,点击Next

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_18

5)指定维度字段,并点击Next

kylin 配置连接hive Keytab验证 kylin和hive_大数据_19

6)指定度量字段,并点击Next

kylin 配置连接hive Keytab验证 kylin和hive_字段_20

7)指定事实表分区字段(仅支持时间分区),点击Save按钮,model创建完毕

 4 构建cube

1)点击new, 并点击new cube

kylin 配置连接hive Keytab验证 kylin和hive_字段_21

2)填写cube信息,选择cube所依赖的model,并点击next

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_22

3)选择所需的维度,如下图所示

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_23

kylin 配置连接hive Keytab验证 kylin和hive_kylin_24

kylin 配置连接hive Keytab验证 kylin和hive_kylin_25

4)选择所需度量值,如下图所示

kylin 配置连接hive Keytab验证 kylin和hive_字段_26

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_27

 

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_28

5)cube自动合并设置,cube需按照日期分区字段每天进行构建,每次构建的结果会保存在Hbase中的一张表内,为提高查询效率,需将每日的cube进行合并,此处可设置合并周期。

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_29

6)Kylin高级配置(优化相关,暂时跳过)

kylin 配置连接hive Keytab验证 kylin和hive_大数据_30

7)Kylin相关属性配置覆盖

kylin 配置连接hive Keytab验证 kylin和hive_字段_31

8)Cube信息总览,点击Save,Cube创建完成

kylin 配置连接hive Keytab验证 kylin和hive_kylin_32

 到此,cube配置完毕,开始计算。

9)构建Cube(计算),点击对应Cube的action按钮,选择build

kylin 配置连接hive Keytab验证 kylin和hive_字段_33

10)选择要构建的时间区间,点击Submit

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_34

11)点击Monitor查看构建进度

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_35

 5 使用进阶

1)每日全量维度表及拉链维度表重复Key问题如何处理

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_36

 查看报错日志

kylin 配置连接hive Keytab验证 kylin和hive_kylin_37

错误原因分析:

上述错误原因是model中的维度表dim_user_info为拉链表、dim_sku_info(dim_sku_info_view)为每日全量表,故使用整张表作为维度表,必然会出现订单明细表中同一个user_id或者sku_id对应多条数据的问题,针对上述问题,有以下解决方案。

在hive客户端为拉链表以及每日全量维度表创建视图,在创建视图时对数据加以过滤,保证从视图中查出的数据是一份全量最新的数据即可。

(1)创建维度表视图

--拉链维度表视图

create view dim_user_info_view as select * from dim_user_info where dt='9999-99-99';


--全量维度表视图(注意排除复杂数据类型字段)

create view dim_sku_info_view

as

select

    id,

    price,

    sku_name,

    sku_desc,

    weight,

    is_sale,

    spu_id,

    spu_name,

    category3_id,

    category3_name,

    category2_id,

    category2_name,

    category1_id,

    category1_name,

    tm_id,

    tm_name,

    create_time

from dim_sku_info

where dt=date_add(current_date,-1);


--当前情形我们先创建一个2020-06-15的视图,由于之前已经创建了dim_sku_info_view,故无需重新创建,修改之前的视图即可。

alter view dim_sku_info_view

as

select

    id,

    price,

    sku_name,

    sku_desc,

    weight,

    is_sale,

    spu_id,

    spu_name,

    category3_id,

    category3_name,

    category2_id,

    category2_name,

    category1_id,

    category1_name,

    tm_id,

    tm_name,

    create_time

from dim_sku_info

where dt='2020-06-15';

kylin 配置连接hive Keytab验证 kylin和hive_大数据_38

(2)在DataSource中导入新创建的视图,之前的维度表,可选择性删除。

kylin 配置连接hive Keytab验证 kylin和hive_字段_39

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_40

kylin 配置连接hive Keytab验证 kylin和hive_kylin_41

kylin 配置连接hive Keytab验证 kylin和hive_大数据_42

kylin 配置连接hive Keytab验证 kylin和hive_kylin_43

kylin 配置连接hive Keytab验证 kylin和hive_kylin_44

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_45

(3)重新创建model、cube。

kylin 配置连接hive Keytab验证 kylin和hive_kylin_46

kylin 配置连接hive Keytab验证 kylin和hive_字段_47

 接下来创建model、cube,和前面的步骤完全一样。

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_48

2)如何实现每日自动构建cube

Kylin提供了Restful API,因次我们可以将构建cube的命令写到脚本中,将脚本交给azkaban或者oozie这样的调度工具,以实现定时调度的功能。

脚本如下:

#!/bin/bash
cube_name=order_cube
do_date=`date -d '-1 day' +%F`

#获取00:00时间戳
start_date_unix=`date -d "$do_date 08:00:00" +%s`
start_date=$(($start_date_unix*1000))

#获取24:00的时间戳
stop_date=$(($start_date+86400000))

curl -X PUT -H "Authorization: Basic QURNSU46S1lMSU4=" -H 'Content-Type: application/json' -d '{"startTime":'$start_date', "endTime":'$stop_date', "buildType":"BUILD"}' http://hadoop102:7070/kylin/api/cubes/$cube_name/build

6 Zepplin

(1)将zeppelin-0.8.0-bin-all.tgz上传至Linux

(2)解压zeppelin-0.8.0-bin-all.tgz之/opt/module

[zhang@hadoop102 sorfware]$ tar -zxvf zeppelin-0.8.0-bin-all.tgz -C /opt/module/

kylin 配置连接hive Keytab验证 kylin和hive_大数据_49

zeppelin的web默认端口号为8080,可能会和前面配置的zookeeper的配置端口相冲突,所以先修改一下端口号。

 [zhang@hadoop102 conf]$ mv zeppelin-site.xml.template zeppelin-site.xml
[zhang@hadoop102 conf]$ vim zeppelin-site.xml

kylin 配置连接hive Keytab验证 kylin和hive_字段_50

 启动

[zhang@hadoop102 zeppelin]$ bin/zeppelin-daemon.sh start

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_51

web端访问并配置Zepplin支持Kylin

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_52

 搜索Kylin插件并修改相应的配置

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_53

 

kylin 配置连接hive Keytab验证 kylin和hive_kylin_54

 案例实操

(1)点击Notebook创建新的note

kylin 配置连接hive Keytab验证 kylin和hive_字段_55

 

kylin 配置连接hive Keytab验证 kylin和hive_复杂数据类型_56

结果展示

kylin 配置连接hive Keytab验证 kylin和hive_kylin_57

 

kylin 配置连接hive Keytab验证 kylin和hive_hadoop_58