项目实战从0到1之hive(24)企业级数据仓库构建(六):数仓理论及数仓搭建
发布日期:2021-05-14 00:17:06 浏览次数:9 分类:博客文章

本文共 30022 字,大约阅读时间需要 100 分钟。

������������������

1.1 ������������������
1.2 ���������������������������������
1.3 ������������������1.3.1 ���������

  • ODS������������ods_������
  • DWD������������dwd_dim/fact_������
  • DWS������������dws_������
  • DWT������������dwt_���������
  • ADS������������ads_������
  • ������������������xxx_tmp
  • ���������������������log���������

1.3.2 ������������

  • ���������_to_������_db/log.sh
  • ���������������������log���������������������������������db���������

������������������
2.1 ������������
2.1.1 ������������
1���������
���������������������������������������������������������������������������������������������������������
2���������
������������������������������������������������������������������������������������������������
������������������������������������

  • ���1������������������������������������������������������������
  • ���2������������������������������������������������������������������������������������������������
  • ���3���������������������������������������������������������������������

3���������

������������������������������������������������ Join ������������������������
4���������
������������������������������������(1NF)���������������(2NF)���������������(3NF)���������-������������(BCNF)���������������(4NF)���������������(5NF)
2.1.2 ������������
2.1.3 ���������������
2.2 ���������������������������
��������������������������������������������������������������������� OLTP���on-line transactionprocessing������������������������ OLAP���On-Line Analytical Processing���

  • OLTP ���������������������������������������������������������������������������������������������������������������
  • OLAP ���������������������������������������������������������������������������������������������������������������������������������

������������������������������������������

2.2.1 ������������
���������������������������������������������������������3NF������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������ OLTP ���������������������������������������������������������������������������������������������������������������������������
��������������������������������������������� OLAP ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������������������
2.2.2 ������������
���������������������������������������������������������������������������������������������
2.3 ���������������������
2.3.1 ���������
������������������������������������������������������������������������������������������������������������������
������������������������������������������������
������������������

  • ������������������������������������������������������������
  • ������������������������������������������������< 10 ������
  • ������������������������������

������������������

2.3.2 ���������
������������������������������������������������������������������������������������������������
���������������������������������������������������������������������������������������������������������������
���������������������������������������
������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������
���������������������

  • ������������
  • ���������������������������������
  • ���������������������������������������������

1���������������������

������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
2���������������������������
���������������������������������������������������������������������������������������������������������������������������������������������������������������
3���������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
2.4 ������������������������������������
2.4.1 ODS ���

  • ���1������������������������������������������������������������������������
  • ���2������������������������������������������������������������������������ 100G������������������ 10G ���������
  • ���3������������������������������������������������

2.4.2 DWD ���

DWD ������������������������������������������������������������������������������������������
���������������������������������������������
������������������ ��� ������������ ��� ������������ ��� ������������

  • ���1���������������������
    ���������������������������������������������������������������������������������������������������������������������������������������������������������������
  • ���2���������������
    ���������������������������������������������������������������������������������������������
    ������������������������������������������������������������������������������������������������������������������������������������������������
    ������������������������������
    ������������������������������������������������������������������������������������
    ������������������������������������������������������������
    ������������������������������������������������������������
  • ���3���������������
    ������������������������������������������������������������������������������������������������������
  • ���4���������������
    ���������������������������������������������������������������������������������������������������
    ��� DWD ������������������������������������������������������������������������������������������������������������������������������������������������������������������

���������������������������������������������DWS���DWT ��� ADS ��� ���������������������������������
DWS ��� DWT ������������������������������������������������������������������������������������������������������������
2.4.3 DWS ���
��������������������������������������������������� DWT ���������������������������������������������������������������������������������������������������������������������������
2.4.4 DWT ���
���������������������������������������������������������������������������������������������������������������������������
2.4.5 ADS ���
���������������������������������������������������
������������������ - ODS ���

  • 1���������������������������������������������������������������������
  • 2��������������� LZO ������������������������������������100G ��������������������� 10G ������
  • 3���������������������������������������������������������������������������������������������
  • 4������������������������������������������������������������������������������������������������������������������������������������

3.1 ���������������
1������������������
show databases;2������������������
create database gmall;3������������������
use gmall;3.2 ODS ���������������������������
3.2.1 ��������������������� ods_start_log
1������������������������ lzo��� ��������� text��������� json ������������������

drop table if exists ods_start_log;create external table ods_start_log (`line` string)PARTITIONED BY (`dt` string)STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'LOCATION '/warehouse/gmall/ods/ods_start_log';������ Hive ��� LZO ���������https://cwiki.apache.org/confluence/display/Hive/LanguageManual+LZO

2���������������

load data inpath '/origin_data/gmall/log/topic_start/2020-03-10' into table gmall.ods_start_log partition(dt='2020-03-10');��������������������������������� YYYY-MM-DD ��������������� Hive ���������������������������

3���������������������������

select * from ods_start_log where dt='2020-03-10' limit 2;

4������ lzo ������������������������

hadoop jar /opt/modules/hadoop/share/hadoop/common/hadoop-lzo-0.4.20.jarcom.hadoop.compression.lzo.DistributedLzoIndexer/warehouse/gmall/ods/ods_start_log/dt=2020-03-10

3.2.2 ��������������������� ods_event_log

1������������������������ lzo ������������ text��������� json ������������������

drop table if exists ods_event_log;create external table ods_event_log(`line` string)PARTITIONED BY (`dt` string)STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'LOCATION '/warehouse/gmall/ods/ods_event_log';

2���������������

load data inpath '/origin_data/gmall/log/topic_event/2020-03-10'into table gmall.ods_event_log partition(dt='2020-03-10');��������������������������������� YYYY-MM-DD ��������������� Hive ���������������������������

3���������������������������

select * from ods_event_log where dt="2020-03-10" limit 2;

4������ lzo ������������������������

hadoop jar /opt/module/hadoop-2.7.2/share/hadoop/common/hadoop-lzo-0.4.20.jar com.hadoop.compression.lzo.DistributedLzoIndexer/warehouse/gmall/ods/ods_event_log/dt=2020-03-10

3.2.3 Shell ������������������������������

���1���������������������������
���2������������������������
���3������������ ` ������������������������
���4���������������������������������������������������
���5������������������������������������������������������
3.2.4 ODS ���������������������
1��� vim hdfs_to_ods_log.sh
������������������������������

#!/bin/bash# ������������������������APP=gmallhive=/opt/modules/hive/bin/hive# ������������������������������������������������������������������������������������������������if [ -n "$1" ] ;thendo_date=$1elsedo_date=`date -d "-1 day" +%F`fiecho "===��������������� $do_date==="sql="load data inpath '/origin_data/gmall/log/topic_start/$do_date' overwriteinto table ${APP}.ods_start_log partition(dt='$do_date');load data inpath '/origin_data/gmall/log/topic_event/$do_date' overwriteinto table ${APP}.ods_event_log partition(dt='$do_date');"$hive -e "$sql"hadoop jar /opt/modules/hadoop/share/hadoop/common/hadoop-lzo-0.4.20.jarcom.hadoop.compression.lzo.DistributedLzoIndexer/warehouse/gmall/ods/ods_start_log/dt=$do_datehadoop jar /opt/modules/hadoop/share/hadoop/common/hadoop-lzo-0.4.20.jarcom.hadoop.compression.lzo.DistributedLzoIndexer/warehouse/gmall/ods/ods_event_log/dt=$do_date

2���������������������������

chmod 777 hdfs_to_ods_log.sh

3���������������

hdfs_to_ods_log.sh 2020-03-11

4���������������������

select * from ods_start_log where dt='2020-03-11' limit 2;select * from ods_event_log where dt='2020-03-11' limit 2;

5���������������������

������������������������������������ 30 ���~1 ���
3.3 ODS ���������������������
3.3.1 ������������������������������

drop table if exists ods_order_info;create external table ods_order_info (`id` string COMMENT '���������',`final_total_amount` decimal(10,2) COMMENT '������������',`order_status` string COMMENT '������������',`user_id` string COMMENT '������ id',`out_trade_no` string COMMENT '���������������',`create_time` string COMMENT '������������',`operate_time` string COMMENT '������������',`province_id` string COMMENT '������ ID',`benefit_reduce_amount` decimal(10,2) COMMENT '������������',`original_total_amount` decimal(10,2) COMMENT '������������',`feight_fee` decimal(10,2) COMMENT '������') COMMENT '���������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_order_info/';

3.3.2 ���������������������������

drop table if exists ods_order_detail;create external table ods_order_detail(`id` string COMMENT '������������',`order_id` string COMMENT '���������',`user_id` string COMMENT '������ id',`sku_id` string COMMENT '������ id',`sku_name` string COMMENT '������������',`order_price` decimal(10,2) COMMENT '������������',`sku_num` bigint COMMENT '������������',`create_time` string COMMENT '������������') COMMENT '���������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_order_detail/';

3.3.3 SKU ���������������������

drop table if exists ods_sku_info;create external table ods_sku_info(`id` string COMMENT 'skuId',`spu_id` string COMMENT 'spuid',`price` decimal(10,2) COMMENT '������',`sku_name` string COMMENT '������������',`sku_desc` string COMMENT '������������',`weight` string COMMENT '������',`tm_id` string COMMENT '������ id',`category3_id` string COMMENT '������ id',`create_time` string COMMENT '������������') COMMENT 'SKU ���������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'

3.3.4 ������������������������������

drop table if exists ods_user_info;create external table ods_user_info(`id` string COMMENT '������ id',`name` string COMMENT '������',`birthday` string COMMENT '������',`gender` string COMMENT '������',`email` string COMMENT '������',`user_level` string COMMENT '������������',`create_time` string COMMENT '������������',`operate_time` string COMMENT '������������') COMMENT '���������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_user_info/';

3.3.5 ���������������������������������

drop table if exists ods_base_category1;create external table ods_base_category1(`id` string COMMENT 'id',`name` string COMMENT '������') COMMENT '���������������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_base_category1/';

3.3.6 ���������������������������������

drop table if exists ods_base_category2;create external table ods_base_category2(`id` string COMMENT ' id',`name` string COMMENT '������',category1_id string COMMENT '������������ id') COMMENT '���������������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_base_category2/';

3.3.7 ���������������������������������

drop table if exists ods_base_category3;create external table ods_base_category3(`id` string COMMENT ' id',`name` string COMMENT '������',category2_id string COMMENT '������������ id') COMMENT '���������������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_base_category3/';

3.3.8 ���������������������������

drop table if exists ods_payment_info;create external table ods_payment_info(`id` bigint COMMENT '������',`out_trade_no` string COMMENT '������������������',`order_id` string COMMENT '������������',`user_id` string COMMENT '������������',`alipay_trade_no` string COMMENT '���������������������������',`total_amount` decimal(16,2) COMMENT '������������',`subject` string COMMENT '������������',`payment_type` string COMMENT '������������',`payment_time` string COMMENT '������������') COMMENT '���������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_payment_info/';

3.3.9 ���������������������

drop table if exists ods_base_province;create external table ods_base_province (`id` bigint COMMENT '������',`name` string COMMENT '������������',`region_id` string COMMENT '������ ID',`area_code` string COMMENT '������������',`iso_code` string COMMENT 'iso ������') COMMENT '���������'row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_base_province/';

3.3.10 ���������������������

drop table if exists ods_base_region;create external table ods_base_region (`id` bigint COMMENT '������',`region_name` string COMMENT '������������') COMMENT '���������'row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_base_region/';

3.3.11 ���������������������

drop table if exists ods_base_trademark;create external table ods_base_trademark (`tm_id` bigint COMMENT '������',`tm_name` string COMMENT '������������') COMMENT '���������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_base_trademark/';

3.3.12 ���������������������������

drop table if exists ods_order_status_log;create external table ods_order_status_log (`id` bigint COMMENT '������',`order_id` string COMMENT '������ ID',`order_status` string COMMENT '������������',`operate_time` string COMMENT '������������') COMMENT '���������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_order_status_log/';

3.3.13 SPU ���������������������

drop table if exists ods_spu_info;create external table ods_spu_info(`id` string COMMENT 'spuid',`spu_name` string COMMENT 'spu ������',`category3_id` string COMMENT '������ id',`tm_id` string COMMENT '������ id') COMMENT 'SPU ���������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_spu_info/';

3.3.14 ���������������������������

create external table ods_comment_info(`id` string COMMENT '������',`user_id` string COMMENT '������ ID',`sku_id` string COMMENT '������ sku',`spu_id` string COMMENT '������ spu',`order_id` string COMMENT '������ ID',`appraise` string COMMENT '������',`create_time` string COMMENT '������������') COMMENT '���������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_comment_info/';

3.3.15 ���������������������

drop table if exists ods_order_refund_info;create external table ods_order_refund_info(`id` string COMMENT '������',`user_id` string COMMENT '������ ID',`order_id` string COMMENT '������ ID',`sku_id` string COMMENT '������ ID',`refund_type` string COMMENT '������������',`refund_num` bigint COMMENT '������������',`refund_amount` decimal(16,2) COMMENT '������������',`refund_reason_type` string COMMENT '������������������',`create_time` string COMMENT '������������') COMMENT '���������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_order_refund_info/';

3.3.16 ���������������������

drop table if exists ods_cart_info;create external table ods_cart_info(`id` string COMMENT '������',`user_id` string COMMENT '������ id',`sku_id` string COMMENT 'skuid',`cart_price` string COMMENT '������������������������',`sku_num` string COMMENT '������',`sku_name` string COMMENT 'sku ������ (������)',`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'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_cart_info/';

3.3.17 ���������������������������

drop table if exists ods_favor_info;create external table ods_favor_info(`id` string COMMENT '������',`user_id` string COMMENT '������ id',`sku_id` string COMMENT 'skuid',`spu_id` string COMMENT 'spuid',`is_cancel` string COMMENT '������������',`create_time` string COMMENT '������������',`cancel_time` string COMMENT '������������') COMMENT '���������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_favor_info/';

3.3.18 ���������������������������������������

drop table if exists ods_coupon_use;create external table ods_coupon_use(`id` string COMMENT '������',`coupon_id` string COMMENT '��������� ID',`user_id` string COMMENT 'skuid',`order_id` string COMMENT 'spuid',`coupon_status` string COMMENT '���������������',`get_time` string COMMENT '������������',`using_time` string COMMENT '������������(������)',`used_time` string COMMENT '������������(������)') COMMENT '������������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_coupon_use/';

3.3.19 ������������������������

drop table if exists ods_coupon_info;create external table ods_coupon_info(`id` string COMMENT '���������������',`coupon_name` string COMMENT '���������������',`coupon_type` string COMMENT '��������������� 1 ��������� 2 ��������� 3 ��������� 4 ���������������',`condition_amount` string COMMENT '���������',`condition_num` string COMMENT '���������',`activity_id` string COMMENT '������������',`benefit_amount` string COMMENT '���������',`benefit_discount` string COMMENT '������',`create_time` string COMMENT '������������',`range_type` string COMMENT '������������ 1��������� 2��������� 3���������',`spu_id` string COMMENT '������ id',`tm_id` string COMMENT '������ id',`category3_id` string COMMENT '������ id',`limit_num` string COMMENT '������������������',`operate_time` string COMMENT '������������',`expire_time` string COMMENT '������������') COMMENT '������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_coupon_info/';

3.3.20 ���������������������

drop table if exists ods_activity_info;create external table ods_activity_info(`id` string COMMENT '������',`activity_name` string COMMENT '������������',`activity_type` string COMMENT '������������',`start_time` string COMMENT '������������',`end_time` string COMMENT '������������',`create_time` string COMMENT '������������') COMMENT '���������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_activity_info/';

3.3.21 ���������������������������������

drop table if exists ods_activity_order;create external table ods_activity_order(`id` string COMMENT '������',`activity_id` string COMMENT '��������� ID',`order_id` string COMMENT 'skuid',`create_time` string COMMENT '������������') COMMENT '���������������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_activity_order/';

3.3.22 ���������������������������

drop table if exists ods_activity_rule;create external table ods_activity_rule(`id` string COMMENT '������',`activity_id` string COMMENT '������ ID',`condition_amount` string COMMENT '������������',`condition_num` string COMMENT '������������',`benefit_amount` string COMMENT '������������',`benefit_discount` string COMMENT '������������',`benefit_level` string COMMENT '������������') COMMENT '���������������'PARTITIONED BY (`dt` string)row format delimited fields terminated by '\t'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_activity_rule/';

3.3.23 ���������������������������

drop table if exists ods_base_dic;create external table ods_base_dic(`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'STORED ASINPUTFORMAT 'com.hadoop.mapred.DeprecatedLzoTextInputFormat'OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'location '/warehouse/gmall/ods/ods_base_dic/';

3.3.24 ODS ���������������������1���vim hdfs_to_ods_db.sh

������������������������������

#!/bin/bashAPP=gmallhive=/opt/modules/hive/bin/hive# ������������������������������������������������������������������������������������������������if [ -n "$2" ] ;thendo_date=$2elsedo_date=`date -d "-1 day" +%F`fisql1="load data inpath '/origin_data/$APP/db/order_info/$do_date' OVERWRITE into table${APP}.ods_order_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/order_detail/$do_date' OVERWRITE into table${APP}.ods_order_detail partition(dt='$do_date');load data inpath '/origin_data/$APP/db/sku_info/$do_date' OVERWRITE into table${APP}.ods_sku_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/user_info/$do_date' OVERWRITE into table${APP}.ods_user_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/payment_info/$do_date' OVERWRITE into table${APP}.ods_payment_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/base_category1/$do_date' OVERWRITE into table${APP}.ods_base_category1 partition(dt='$do_date');load data inpath '/origin_data/$APP/db/base_category2/$do_date' OVERWRITE into table${APP}.ods_base_category2 partition(dt='$do_date');load data inpath '/origin_data/$APP/db/base_category3/$do_date' OVERWRITE into table${APP}.ods_base_category3 partition(dt='$do_date');load data inpath '/origin_data/$APP/db/base_trademark/$do_date' OVERWRITE into table${APP}.ods_base_trademark partition(dt='$do_date');load data inpath '/origin_data/$APP/db/activity_info/$do_date' OVERWRITE into table${APP}.ods_activity_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/activity_order/$do_date' OVERWRITE into table${APP}.ods_activity_order partition(dt='$do_date');load data inpath '/origin_data/$APP/db/cart_info/$do_date' OVERWRITE into table${APP}.ods_cart_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/comment_info/$do_date' OVERWRITE into table${APP}.ods_comment_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/coupon_info/$do_date' OVERWRITE into table${APP}.ods_coupon_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/coupon_use/$do_date' OVERWRITE into table${APP}.ods_coupon_use partition(dt='$do_date');load data inpath '/origin_data/$APP/db/favor_info/$do_date' OVERWRITE into table${APP}.ods_favor_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/order_refund_info/$do_date' OVERWRITE into table${APP}.ods_order_refund_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/order_status_log/$do_date' OVERWRITE into table${APP}.ods_order_status_log partition(dt='$do_date');load data inpath '/origin_data/$APP/db/spu_info/$do_date' OVERWRITE into table${APP}.ods_spu_info partition(dt='$do_date');load data inpath '/origin_data/$APP/db/activity_rule/$do_date' OVERWRITE into table${APP}.ods_activity_rule partition(dt='$do_date');load data inpath '/origin_data/$APP/db/base_dic/$do_date' OVERWRITE into table${APP}.ods_base_dic partition(dt='$do_date');"sql2="load data inpath '/origin_data/$APP/db/base_province/$do_date' OVERWRITE into table${APP}.ods_base_province;load data inpath '/origin_data/$APP/db/base_region/$do_date' OVERWRITE into table${APP}.ods_base_region;"case $1 in"first"){$hive -e "$sql1"$hive -e "$sql2"};;"all"){$hive -e "$sql1"};;esac

2���������������

chmod 770 hdfs_to_ods_db.sh

3���������������

hdfs_to_ods_db.sh first 2020-03-10

4���������������

hdfs_to_ods_db.sh all 2020-03-11

5���������������������������������

select * from ods_order_detail where dt='2020-03-11';

���������

���������������������������ODS���DWD���������������������������������������������������������������������DWD���DWS���DWT���������������������������������������

上一篇:项目实战从0到1之hive(25)企业级数据仓库构建(七):搭建DWD 层
下一篇:项目实战从0到1之hive(23)企业级数据仓库构建(五):数据仓库项目实战

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月26日 05时55分13秒