目标:阅读ODS申明分区的代码及实现测试
路径
实施
代码讲解
step1:为什么要申明分区?
表的分区数据由Sqoop采集到HDFS生成AVRO文件
/data/dw/ods/one_make/full_imp/ciss4.ciss_base_areas/20210101/part-m-00000.avro
HiveSQL基于表的目录实现了分区表的创建
create external table if not exists one_make_ods.ciss_base_areas
partitioned by (dt string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
tblproperties ('avro.schema.url'='hdfs:///data/dw/ods/one_make/avsc/CISS4_CISS_BASE_AREAS.avsc')
location '/data/dw/ods/one_make/full_imp/ciss4.ciss_base_areas'
但是Hive中没有对应分区的元数据,无法查询到数据
step2:怎么申明分区?
Alter Table
alter table 表名 add if not exists partition (dt='值')
location 'HDFS上的分区路径'
例如
alter table one_make_ods.ciss_base_areas add if not exists partition (dt='20210101')
location '/data/dw/ods/one_make/full_imp/ciss4.ciss_base_areas/20210101'
step3:如何自动化实现每个表的分区的申明?
代码测试
运行代码,查看结果
小结
目标:理解ODS层与DWD层的区别
路径
实施
内容区别
设计区别
实现区别
ODS层建表:基于avsc文件指定Schema建表
create external table if not exists one_make_ods.ciss_base_areas
partitioned by (dt string)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
STORED AS INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
tblproperties ('avro.schema.url'='hdfs:///data/dw/ods/one_make/avsc/CISS4_CISS_BASE_AREAS.avsc')
location '/data/dw/ods/one_make/full_imp/ciss4.ciss_base_areas'
DWD层建表:自己指定每个字段的Schema建表
create external table if not exists one_make_dwd.ciss_base_areas(
ID string,
AREANAME string,
PARENTID string,
SHORTNAME string,
LNG string,
LAT string,
RANK bigint,
POSITION string,
SORT bigint
) partitioned by (dt string)
stored as orc
location '/data/dw/dwd/one_make/ciss_base_areas';
小结
目标:掌握DWD层的构建需求
路径
实施
整体需求:将ODS层的数据表直接加载到DWD层
insert into dwd partition (dt = '20210101')
select
*
from ods
where dt=20210101
建库需求:创建DWD层数据库one_make_dwd
建表需求:将ODS层中的每一张表创建一张对应的DWD层的表
问题1:建表的语法是什么?
create external table dwd.tbname(
字段名 字段类型 字段注释
)
partitioned by (dt string)
location '/data/dw/dwd/one_make/ciss_base_areas';
问题2:表的名称名是什么,怎么获取?
问题3:表的注释怎么来?
问题4:表的字段怎么获取?
问题5:Oracle中的字段类型如果与Hive中的类型不一致怎么办?
小结
目标:阅读DWD建库代码及实现测试
路径
实施
代码讲解
step1:DWD层的数据库名称是什么,建库的语法是什么?
create database if not exists one_make_dwd;
step2:如何实现DWD层数据库的构建?
cHiveTableFromOracleTable.executeCreateDbHQL(CreateMetaCommon.DWD_NAME)
代码测试
小结
目标:阅读DWD建表代码及实现测试
路径
实施
代码讲解
step1:如何获取所有表名?
allTableName = [i for j in tableNameList for i in j]
step2:建表的语句是什么,哪些是动态变化的?
create external table if not exists one_make_dwd.ciss_base_areas(
ID string comment '字段的注释',
AREANAME string comment '字段的注释',
PARENTID string comment '字段的注释',
SHORTNAME string comment '字段的注释',
LNG string comment '字段的注释',
LAT string comment '字段的注释',
RANK bigint comment '字段的注释',
POSITION string comment '字段的注释',
SORT bigint comment '字段的注释'
)
comment '表的注释'
partitioned by (dt string) stored as orc
location '/data/dw/dwd/one_make/ciss_base_areas';
step3:怎么获取字段信息?
step4:Oracle字段类型与Hive/SparkSQL字段类型不一致怎么办?
step4:HDFS上的路径是什么?
/data/dw/dwd/one_make/tableName
step5:如何实现自动化
代码测试
小结