介绍
hive ODS 层的数据来源是MySQL业务表和服务器的日志数据。由于我们的表过多,我们希望一次性可以建表成功,所以写一个hql脚本(该脚本在hive的gmall库下【没有先创建】创建1张日志表,17张全量表,13张增量表),最后在hive客户端source通过导入命令导入即可 source /opt/tablecreate/CreateHiveODSTable.hql
表的特性:
JSON表
【hive表解析JSON格式的数据】(默认情况下Hive的表无法解析JSON格式,需要手动设定)
- 如果JSON属性和表的字段相同,那么可以正常解析
- 如果JSON属性少于表的字段,那么存在的属性可以正常解析,不存在的字段会设定为null
- 如果JSON属性多于表的字段,那么多于属性不做解析
- 如果JSON属性和表的字段会进行不区分大小写的解析
tsv表
【hive表解析tsv格式的数据】(默认情况下Hive的表无法解析tsv格式,需要手动设定)
对于日志表:
- 数据来源是web服务器采集到Kafka中的json格式文本再采集到hdfs,一般都是json表【按业务数据特点以及json表特性建即可】
对于业务表:
- 增量:数据来源是Maxwell采集到Kafka中的json文本再采集到hdfs,一般都是json表【对照Maxwell数据特点以及json表特性建即可】 全量:数据来源是DataX的tsv格式采集到hdfs,一般都是tsv表【按业务表结构建即可(MySQL)】
参数解析:
PARTITIONED BY (
**分区字段**字段类型)
:- 这个参数用于指定表的分区字段及其数据类型。
- 分区是 Hive 中处理大数据集的一种优化方式,通过分区,可以将数据按特定字段进行切分,从而提高查询效率。
- 示例:
PARTITIONED BY (dt STRING)
表示按照dt
字段进行分区,其中dt
是字符串类型。
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
:- 这个参数指定了表的数据存储格式。
SERDE
是 serialization/deserialization(序列化和反序列化)的缩写。在 Hive 中,不同的数据格式需要不同的 SERDE。- 这里使用的是
JsonSerDe
,它处理 JSON 格式的数据。这意味着在数据读写时会将 JSON 数据转换为 Hive 可识别的格式。
LOCATION '/warehouse/gmall/ods/ods_log_inc/'
:- 这个参数指定了存储该表数据的具体 HDFS 路径。
- 数据会存储在指定的目录中,Hive 对该路径下的数据进行管理。
- 使用这个路径,您可以将数据直接放入 HDFS 的该位置,而 Hive 会识别并管理这些数据。
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec')
:- 这个参数用于指定表的属性。在这个例子中,指定了数据的压缩编码格式。
GzipCodec
表示使用 Gzip 压缩数据,这样可以减少存储空间并提高读取效率。- TBLPROPERTIES 可以添加其他属性,例如表的描述、所有者等。
NULL DEFINED AS ''
:- 这个参数用于定义 NULL 值的表示方式。
- 在此示例中,NULL 值将被视作空字符串
''
。这意味着在查询数据时,如果数据字段为空,Hive 会将其转换为 NULL,反之亦然。
脚本
代码语言:shell复制cd /opt/
mkdir tablecreate
vim CreateHiveODSTable.hql
代码语言:sql复制CREATE DATABASE IF NOT EXISTS gmall;
DROP TABLE IF EXISTS gmall.ods_log_inc;
CREATE EXTERNAL TABLE gmall.ods_log_inc
(
`common` STRUCT<ar :STRING,
ba :STRING,
ch :STRING,
is_new :STRING,
md :STRING,
mid :STRING,
os :STRING,
sid :STRING,
uid :STRING,
vc :STRING> COMMENT '公共信息',
`page` STRUCT<during_time :STRING,
item :STRING,
item_type :STRING,
last_page_id :STRING,
page_id :STRING,
from_pos_id :STRING,
from_pos_seq :STRING,
refer_id :STRING> COMMENT '页面信息',
`actions` ARRAY<STRUCT<action_id:STRING,
item:STRING,
item_type:STRING,
ts:BIGINT>> COMMENT '动作信息',
`displays` ARRAY<STRUCT<display_type :STRING,
item :STRING,
item_type :STRING,
`pos_seq` :STRING,
pos_id :STRING>> COMMENT '曝光信息',
`start` STRUCT<entry :STRING,
first_open :BIGINT,
loading_time :BIGINT,
open_ad_id :BIGINT,
open_ad_ms :BIGINT,
open_ad_skip_ms :BIGINT> COMMENT '启动信息',
`err` STRUCT<error_code:BIGINT,
msg:STRING> COMMENT '错误信息',
`ts` BIGINT COMMENT '时间戳'
) COMMENT '活动信息表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_log_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_activity_info_full;
CREATE EXTERNAL TABLE gmall.ods_activity_info_full
(
`id` STRING COMMENT '活动id',
`activity_name` STRING COMMENT '活动名称',
`activity_type` STRING COMMENT '活动类型',
`activity_desc` STRING COMMENT '活动描述',
`start_time` STRING COMMENT '开始时间',
`end_time` STRING COMMENT '结束时间',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '活动信息表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_activity_info_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_activity_rule_full;
CREATE EXTERNAL TABLE gmall.ods_activity_rule_full
(
`id` STRING COMMENT '编号',
`activity_id` STRING COMMENT '活动ID',
`activity_type` STRING COMMENT '活动类型',
`condition_amount` DECIMAL(16, 2) COMMENT '满减金额',
`condition_num` BIGINT COMMENT '满减件数',
`benefit_amount` DECIMAL(16, 2) COMMENT '优惠金额',
`benefit_discount` DECIMAL(16, 2) COMMENT '优惠折扣',
`benefit_level` STRING COMMENT '优惠级别',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '活动规则表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_activity_rule_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_base_category1_full;
CREATE EXTERNAL TABLE gmall.ods_base_category1_full
(
`id` STRING COMMENT '编号',
`name` STRING COMMENT '分类名称',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '一级品类表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_base_category1_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_base_category2_full;
CREATE EXTERNAL TABLE gmall.ods_base_category2_full
(
`id` STRING COMMENT '编号',
`name` STRING COMMENT '二级分类名称',
`category1_id` STRING COMMENT '一级分类编号',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '二级品类表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_base_category2_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_base_category3_full;
CREATE EXTERNAL TABLE gmall.ods_base_category3_full
(
`id` STRING COMMENT '编号',
`name` STRING COMMENT '三级分类名称',
`category2_id` STRING COMMENT '二级分类编号',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '三级品类表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_base_category3_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_base_dic_full;
CREATE EXTERNAL TABLE gmall.ods_base_dic_full
(
`dic_code` STRING COMMENT '编号',
`dic_name` STRING COMMENT '编码名称',
`parent_code` STRING COMMENT '父编号',
`create_time` STRING COMMENT '创建日期',
`operate_time` STRING COMMENT '修改日期'
) COMMENT '编码字典表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_base_dic_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_base_province_full;
CREATE EXTERNAL TABLE gmall.ods_base_province_full
(
`id` STRING COMMENT '编号',
`name` STRING COMMENT '省份名称',
`region_id` STRING COMMENT '地区ID',
`area_code` STRING COMMENT '地区编码',
`iso_code` STRING COMMENT '旧版国际标准地区编码,供可视化使用',
`iso_3166_2` STRING COMMENT '新版国际标准地区编码,供可视化使用',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '省份表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_base_province_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_base_region_full;
CREATE EXTERNAL TABLE gmall.ods_base_region_full
(
`id` STRING COMMENT '地区ID',
`region_name` STRING COMMENT '地区名称',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '地区表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_base_region_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_base_trademark_full;
CREATE EXTERNAL TABLE gmall.ods_base_trademark_full
(
`id` STRING COMMENT '编号',
`tm_name` STRING COMMENT '品牌名称',
`logo_url` STRING COMMENT '品牌LOGO的图片路径',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '品牌表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_base_trademark_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_cart_info_full;
CREATE EXTERNAL TABLE gmall.ods_cart_info_full
(
`id` STRING COMMENT '编号',
`user_id` STRING COMMENT '用户ID',
`sku_id` STRING COMMENT 'SKU_ID',
`cart_price` DECIMAL(16, 2) COMMENT '放入购物车时价格',
`sku_num` BIGINT COMMENT '数量',
`img_url` BIGINT COMMENT '商品图片地址',
`sku_name` STRING COMMENT 'SKU名称 (冗余)',
`is_checked` STRING COMMENT '是否被选中',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间',
`is_ordered` STRING COMMENT '是否已经下单',
`order_time` STRING COMMENT '下单时间'
) COMMENT '购物车全量表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_cart_info_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_coupon_info_full;
CREATE EXTERNAL TABLE gmall.ods_coupon_info_full
(
`id` STRING COMMENT '购物券编号',
`coupon_name` STRING COMMENT '购物券名称',
`coupon_type` STRING COMMENT '购物券类型 1 现金券 2 折扣券 3 满减券 4 满件打折券',
`condition_amount` DECIMAL(16, 2) COMMENT '满额数',
`condition_num` BIGINT COMMENT '满件数',
`activity_id` STRING COMMENT '活动编号',
`benefit_amount` DECIMAL(16, 2) COMMENT '减免金额',
`benefit_discount` DECIMAL(16, 2) COMMENT '折扣',
`create_time` STRING COMMENT '创建时间',
`range_type` STRING COMMENT '范围类型 1、商品(SPUID) 2、品类(三级品类id) 3、品牌',
`limit_num` BIGINT COMMENT '最多领用次数',
`taken_count` BIGINT COMMENT '已领用次数',
`start_time` STRING COMMENT '可以领取的开始时间',
`end_time` STRING COMMENT '可以领取的结束时间',
`operate_time` STRING COMMENT '修改时间',
`expire_time` STRING COMMENT '过期时间',
`range_desc` STRING COMMENT '范围描述'
) COMMENT '优惠券信息表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_coupon_info_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_sku_attr_value_full;
CREATE EXTERNAL TABLE gmall.ods_sku_attr_value_full
(
`id` STRING COMMENT '编号',
`attr_id` STRING COMMENT '平台属性ID',
`value_id` STRING COMMENT '平台属性值ID',
`sku_id` STRING COMMENT 'SKU_ID',
`attr_name` STRING COMMENT '平台属性名称',
`value_name` STRING COMMENT '平台属性值名称',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '商品平台属性表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_sku_attr_value_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_sku_info_full;
CREATE EXTERNAL TABLE gmall.ods_sku_info_full
(
`id` STRING COMMENT 'SKU_ID',
`spu_id` STRING COMMENT 'SPU_ID',
`price` DECIMAL(16, 2) COMMENT '价格',
`sku_name` STRING COMMENT 'SKU名称',
`sku_desc` STRING COMMENT 'SKU规格描述',
`weight` DECIMAL(16, 2) COMMENT '重量',
`tm_id` STRING COMMENT '品牌ID',
`category3_id` STRING COMMENT '三级品类ID',
`sku_default_img` STRING COMMENT '默认显示图片地址',
`is_sale` STRING COMMENT '是否在售',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '商品表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_sku_info_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_sku_sale_attr_value_full;
CREATE EXTERNAL TABLE gmall.ods_sku_sale_attr_value_full
(
`id` STRING COMMENT '编号',
`sku_id` STRING COMMENT 'SKU_ID',
`spu_id` STRING COMMENT 'SPU_ID',
`sale_attr_value_id` STRING COMMENT '销售属性值ID',
`sale_attr_id` STRING COMMENT '销售属性ID',
`sale_attr_name` STRING COMMENT '销售属性名称',
`sale_attr_value_name` STRING COMMENT '销售属性值名称',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '商品销售属性值表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_sku_sale_attr_value_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_spu_info_full;
CREATE EXTERNAL TABLE gmall.ods_spu_info_full
(
`id` STRING COMMENT 'SPU_ID',
`spu_name` STRING COMMENT 'SPU名称',
`description` STRING COMMENT '描述信息',
`category3_id` STRING COMMENT '三级品类ID',
`tm_id` STRING COMMENT '品牌ID',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT 'SPU表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_spu_info_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_promotion_pos_full;
CREATE EXTERNAL TABLE gmall.ods_promotion_pos_full
(
`id` STRING COMMENT '营销坑位ID',
`pos_location` STRING COMMENT '营销坑位位置',
`pos_type` STRING COMMENT '营销坑位类型:banner,宫格,列表,瀑布',
`promotion_type` STRING COMMENT '营销类型:算法、固定、搜索',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '营销坑位表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_promotion_pos_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_promotion_refer_full;
CREATE EXTERNAL TABLE gmall.ods_promotion_refer_full
(
`id` STRING COMMENT '外部营销渠道ID',
`refer_name` STRING COMMENT '外部营销渠道名称',
`create_time` STRING COMMENT '创建时间',
`operate_time` STRING COMMENT '修改时间'
) COMMENT '营销渠道表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT DELIMITED FIELDS TERMINATED BY 't'
NULL DEFINED AS ''
LOCATION '/warehouse/gmall/ods/ods_promotion_refer_full/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_cart_info_inc;
CREATE EXTERNAL TABLE gmall.ods_cart_info_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
user_id :STRING,
sku_id :STRING,
cart_price :DECIMAL(16, 2),
sku_num :BIGINT,
img_url :STRING,
sku_name :STRING,
is_checked :STRING,
create_time :STRING,
operate_time :STRING,
is_ordered :STRING,
order_time:STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '购物车增量表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_cart_info_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_comment_info_inc;
CREATE EXTERNAL TABLE gmall.ods_comment_info_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
user_id :STRING,
nick_name :STRING,
head_img :STRING,
sku_id :STRING,
spu_id :STRING,
order_id :STRING,
appraise :STRING,
comment_txt :STRING,
create_time :STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '评论表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_comment_info_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_coupon_use_inc;
CREATE EXTERNAL TABLE gmall.ods_coupon_use_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
coupon_id :STRING,
user_id :STRING,
order_id :STRING,
coupon_status :STRING,
get_time :STRING,
using_time:STRING,
used_time :STRING,expire_time :STRING,
create_time :STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '优惠券领用表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_coupon_use_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_favor_info_inc;
CREATE EXTERNAL TABLE gmall.ods_favor_info_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
user_id :STRING,
sku_id :STRING,
spu_id :STRING,
is_cancel :STRING,
create_time :STRING,
operate_time:STRING> COMMENT '数据',
`old` MAP<STRING,
STRING> COMMENT '旧值'
) COMMENT '收藏表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_favor_info_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_order_detail_inc;
CREATE EXTERNAL TABLE gmall.ods_order_detail_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
order_id :STRING,
sku_id :STRING,
sku_name :STRING,
img_url :STRING,
order_price:DECIMAL(16, 2),
sku_num :BIGINT,
create_time :STRING,
source_type :STRING,
source_id :STRING,
split_total_amount:DECIMAL(16, 2),
split_activity_amount :DECIMAL(16, 2),
split_coupon_amount:DECIMAL(16, 2),
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,
STRING> COMMENT '旧值'
) COMMENT '订单明细表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_order_detail_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_order_detail_activity_inc;
CREATE EXTERNAL TABLE gmall.ods_order_detail_activity_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
order_id :STRING,
order_detail_id :STRING,
activity_id :STRING,
activity_rule_id :STRING,
sku_id:STRING,
create_time :STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '订单明细活动关联表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_order_detail_activity_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_order_detail_coupon_inc;
CREATE EXTERNAL TABLE gmall.ods_order_detail_coupon_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
order_id :STRING,
order_detail_id :STRING,
coupon_id :STRING,
coupon_use_id :STRING,
sku_id:STRING,
create_time :STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '订单明细优惠券关联表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_order_detail_coupon_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_order_info_inc;
CREATE EXTERNAL TABLE gmall.ods_order_info_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
consignee :STRING,
consignee_tel :STRING,
total_amount :DECIMAL(16, 2),
order_status :STRING,
user_id:STRING,
payment_way :STRING,
delivery_address :STRING,
order_comment :STRING,
out_trade_no :STRING,
trade_body:STRING,
create_time :STRING,
operate_time :STRING,
expire_time :STRING,
process_status :STRING,
tracking_no:STRING,
parent_order_id :STRING,
img_url :STRING,
province_id :STRING,
activity_reduce_amount:DECIMAL(16, 2),
coupon_reduce_amount :DECIMAL(16, 2),
original_total_amount :DECIMAL(16, 2),
freight_fee:DECIMAL(16, 2),
freight_fee_reduce :DECIMAL(16, 2),
refundable_time :DECIMAL(16, 2)> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '订单表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_order_info_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_order_refund_info_inc;
CREATE EXTERNAL TABLE gmall.ods_order_refund_info_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
user_id :STRING,
order_id :STRING,
sku_id :STRING,
refund_type :STRING,
refund_num :BIGINT,
refund_amount:DECIMAL(16, 2),
refund_reason_type :STRING,
refund_reason_txt :STRING,
refund_status :STRING,
create_time:STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '退单表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_order_refund_info_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_order_status_log_inc;
CREATE EXTERNAL TABLE gmall.ods_order_status_log_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
order_id :STRING,
order_status :STRING,
create_time :STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '订单状态流水表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_order_status_log_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_payment_info_inc;
CREATE EXTERNAL TABLE gmall.ods_payment_info_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
out_trade_no :STRING,
order_id :STRING,
user_id :STRING,
payment_type :STRING,
trade_no:STRING,
total_amount :DECIMAL(16, 2),
subject :STRING,
payment_status :STRING,
create_time :STRING,
callback_time:STRING,
callback_content :STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '支付表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_payment_info_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_refund_payment_inc;
CREATE EXTERNAL TABLE gmall.ods_refund_payment_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
out_trade_no :STRING,
order_id :STRING,
sku_id :STRING,
payment_type :STRING,
trade_no :STRING,
total_amount:DECIMAL(16, 2),
subject :STRING,
refund_status :STRING,
create_time :STRING,
callback_time :STRING,
callback_content:STRING,
operate_time :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '退款表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_refund_payment_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
DROP TABLE IF EXISTS gmall.ods_user_info_inc;
CREATE EXTERNAL TABLE gmall.ods_user_info_inc
(
`type` STRING COMMENT '变动类型',
`ts` BIGINT COMMENT '变动时间',
`data` STRUCT<id :STRING,
login_name :STRING,
nick_name :STRING,
passwd :STRING,
name :STRING,
phone_num :STRING,
email:STRING,
head_img :STRING,
user_level :STRING,
birthday :STRING,
gender :STRING,
create_time :STRING,
operate_time:STRING,
status :STRING> COMMENT '数据',
`old` MAP<STRING,STRING> COMMENT '旧值'
) COMMENT '用户表'
PARTITIONED BY (`dt` STRING)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.JsonSerDe'
LOCATION '/warehouse/gmall/ods/ods_user_info_inc/'
TBLPROPERTIES ('compression.codec'='org.apache.hadoop.io.compress.GzipCodec');
加权限
代码语言:shell复制chmod 777 ./CreateHiveODSTable.hql