大数据模块开发----ETL

ETL工作的实质就是从各个数据源提取数据,对数据进行转换,并最终加载填充数据到数据仓库维度建模后的表中。只有当这些维度/事实表被填充好,ETL工作才算完成。

本项目的数据分析过程在hadoop集群上实现,主要应用hive数据仓库工具,因此,采集并经过预处理后的数据,需要加载到hive数据仓库中,以进行后续的分析过程。

1.?创建ODS层数据表1.1.?原始日志数据表

drop table if exists ods_weblog_origin;

create table ods_weblog_origin(

valid string,

remote_addr string,

remote_user string,

time_local string,

request string,

status string,

body_bytes_sent string,

http_referer string,

http_user_agent string)

partitioned by (datestr string)

row format delimited

fields terminated by ‘\001‘;

1.2.?点击流模型pageviews表

drop table if exists ods_click_pageviews;

create table ods_click_pageviews(

session string,

remote_addr string,

remote_user string,

time_local string,

request string,

visit_step string,

page_staylong string,

http_referer string,

http_user_agent string,

body_bytes_sent string,

status string)

partitioned by (datestr string)

row format delimited

fields terminated by ‘\001‘;

1.3.?点击流visit模型表

drop table if exist ods_click_stream_visit;

create table ods_click_stream_visit(

session? ???string,

remote_addr string,

inTime? ?? ?string,

outTime? ???string,

inPage? ?? ?string,

outPage? ???string,

referal? ???string,

pageVisits??int)

partitioned by (datestr string)

row format delimited

fields terminated by ‘\001‘;

2.?导入ODS层数据

load data inpath ‘/weblog/preprocessed/‘ overwrite into table

ods_weblog_origin partition(datestr=‘20130918‘);--数据导入

show partitions ods_weblog_origin;---查看分区

select count(*) from ods_weblog_origin; --统计导入的数据总数

点击流模型的两张表数据导入操作同上。

注:生产环境中应该将数据load命令,写在脚本中,然后配置在azkaban中定时运行,注意运行的时间点,应该在预处理数据完成之后。

3.?生成ODS层明细宽表3.1.?需求实现

整个数据分析的过程是按照数据仓库的层次分层进行的,总体来说,是从ODS原始数据中整理出一些中间表(比如,为后续分析方便,将原始数据中的时间、url等非结构化数据作结构化抽取,将各种字段信息进行细化,形成明细表),然后再在中间表的基础之上统计出各种指标数据。

3.2.?ETL实现

l 建明细表ods_weblog_detail:

drop table ods_weblog_detail;

create table ods_weblog_detail(

valid? ?? ?? ???string, --有效标识

remote_addr? ???string, --来源IP

remote_user? ???string, --用户标识

time_local? ?? ?string, --访问完整时间

daystr? ?? ?? ? string, --访问日期

timestr? ?? ?? ?string, --访问时间

month? ?? ?? ???string, --访问月

day? ?? ?? ?? ? string, --访问日

hour? ?? ?? ?? ?string, --访问时

request? ?? ?? ?string, --请求的url

status? ?? ?? ? string, --响应码

body_bytes_sent string, --传输字节数

http_referer? ? string, --来源url

ref_host? ?? ???string, --来源的host

ref_path? ?? ???string, --来源的路径

ref_query? ?? ? string, --来源参数query

ref_query_id? ? string, --来源参数query的值

http_user_agent string --客户终端标识

)

partitioned by(datestr string);

?

l 通过查询插入数据到明细宽表??ods_weblog_detail中

1、 抽取refer_url到中间表 t_ods_tmp_referurl

也就是将来访url分离出host??path??query??query id

drop table if exists t_ods_tmp_referurl;

create table t_ods_tmp_referurl as

SELECT a.,b.

FROM ods_weblog_origin a

LATERAL VIEW parse_url_tuple(regexp_replace(http_referer, "\"", ""), ‘HOST‘, ‘PATH‘,‘QUERY‘, ‘QUERY:id‘) b as host, path, query, query_id;

注:lateral view用于和split, explode等UDTF一起使用,它能够将一列数据拆成多行数据。

UDTF(User-Defined Table-Generating Functions) 用来解决输入一行输出多行(On-to-many maping) 的需求。Explode也是拆列函数,比如Explode (ARRAY) ,array中的每个元素生成一行。

2、抽取转换time_local字段到中间表明细表 t_ods_tmp_detail

drop table if exists t_ods_tmp_detail;

create table t_ods_tmp_detail as

select b.*,substring(time_local,0,10) as daystr,

substring(time_local,12) as tmstr,

substring(time_local,6,2) as month,

substring(time_local,9,2) as day,

substring(time_local,11,3) as hour

from t_ods_tmp_referurl b;

3、以上语句可以合成一个总的语句

insert into table shizhan.ods_weblog_detail partition(datestr=‘2013-09-18‘)

select c.valid,c.remote_addr,c.remote_user,c.time_local,

substring(c.time_local,0,10) as daystr,

substring(c.time_local,12) as tmstr,

substring(c.time_local,6,2) as month,

substring(c.time_local,9,2) as day,

substring(c.time_local,11,3) as hour,

c.request,c.status,c.body_bytes_sent,c.http_referer,c.ref_host,c.ref_path,c.ref_query,c.ref_query_id,c.http_user_agent

from

(SELECT

a.valid,a.remote_addr,a.remote_user,a.time_local,

a.request,a.status,a.body_bytes_sent,a.http_referer,a.http_user_agent,b.ref_host,b.ref_path,b.ref_query,b.ref_query_id

FROM shizhan.ods_weblog_origin a LATERAL VIEW

parse_url_tuple(regexp_replace(http_referer, "\"", ""), ‘HOST‘, ‘PATH‘,‘QUERY‘, ‘QUERY:id‘) b as ref_host, ref_path, ref_query,

ref_query_id) c;

原文地址:https://blog.51cto.com/14473726/2432523

时间: 2024-07-29 15:15:05

大数据模块开发----ETL的相关文章

大数据模块开发之数据预处理

1. 主要目的过滤"不合规"数据,清洗无意义的数据格式转换和规整根据后续的统计需求,过滤分离出各种不同主题(不同栏目path)的基础数据.2. 实现方式开发一个mr程序WeblogPreProcess(内容太长,见工程代码) public class WeblogPreProcess { static class WeblogPreProcessMapper extends Mapper<LongWritable, Text, Text, NullWritable> { T

大数据模块开发----统计分析

数据仓库建设好以后,用户就可以编写Hive SQL语句对其进行访问并对其中数据进行分析. 在实际生产中,究竟需要哪些统计指标通常由数据需求相关部门人员提出,而且会不断有新的统计需求产生,以下为网站流量分析中的一些典型指标示例. 注:每一种统计指标都可以跟各维度表进行钻取. 1.?流量分析1.1.?多维度统计PV总量按时间维度 -计算每小时pvs,注意gruop by语法 select count(*) as pvs,month,day,hour from ods_weblog_detail gr

大数据模块开发之数据采集

1. 需求在网站web流量日志分析这种场景中,对数据采集部分的可靠性.容错能力要求通常不会非常严苛,因此使用通用的flume日志采集框架完全可以满足需求.2. Flume日志采集系统2.1. Flume采集Flume采集系统的搭建相对简单:1.在服务器上部署agent节点,修改配置文件2.启动agent节点,将采集到的数据汇聚到指定的HDFS目录中针对nginx日志生成场景,如果通过flume(1.6)收集,无论是Spooling Directory Source和Exec Source均不能满

大数据模块开发之结果导出

1. Apache SqoopSqoop是Hadoop和关系数据库服务器之间传送数据的一种工具.它是用来从关系数据库如:MySQL,Oracle到Hadoop的HDFS,并从Hadoop的文件系统导出数据到关系数据库.由Apache软件基金会提供.Sqoop:"SQL 到 Hadoop 和 Hadoop 到SQL".Sqoop工作机制是将导入或导出命令翻译成mapreduce程序来实现.在翻译出的mapreduce中主要是对inputformat和outputformat进行定制.sq

大数据模块开发----数据仓库设计

1.?维度建模基本概念 维度建模(dimensional modeling)是专门用于分析型数据库.数据仓库.数据集市建模的方法.数据集市可以理解为是一种"小型数据仓库". 维度表(dimension) 维度表示你要对数据进行分析时所用的一个量,比如你要分析产品销售情况, 你可以选择按类别来进行分析,或按区域来分析.这样的按..分析就构成一个维度.再比如"昨天下午我在星巴克花费200元喝了一杯卡布奇诺".那么以消费为主题进行分析,可从这段信息中提取三个维度:时间维度

大数据模块开发----结果导出

1.?Apache Sqoop Sqoop是Hadoop和关系数据库服务器之间传送数据的一种工具.它是用来从关系数据库如:MySQL,Oracle到Hadoop的HDFS,并从Hadoop的文件系统导出数据到关系数据库.由Apache软件基金会提供. Sqoop:"SQL 到 Hadoop 和 Hadoop 到SQL".Sqoop工作机制是将导入或导出命令翻译成mapreduce程序来实现. 在翻译出的mapreduce中主要是对inputformat和outputformat进行定制

数据仓库工程师、大数据开发工程师、BI工程师、ETL工程师之间有什么区别?

商务智能.商务智能工程师是商业智能行业的工程师.从需求分析师到数据仓库架构师.ETL工程师.数据分析工程师.报表开发工程师.数据挖掘工程师等,都可以称为BI工程师. ETL工程师:从事系统编程.数据库编程和设计,掌握各种常用编程语言的专业技术人员.也称为数据库工程师. 盲目地解释数据仓库的概念可能并不有趣.让我们从不同的角色开始. 老板:我是一家手机公司的老板.今天我要向董事会汇报.我将准备一份关于用户增长.用户保留率.用户活动以及过去三年中我手机中每个应用程序的使用率的报告.如果下面没有BI,

大数据开发常用的大数据分析软件有什么?

大数据开发常用的大数据分析软件有什么? 大数据研究的出现,为企业.研究机构.政府决策提供了新的行之有效思路和手段,想要做好大数据的管理和分析,一些大数据开发工具的使用是必不可少的,以下是大数据开发过程中常用的工具: 1. Apache Hive Hive是一个建立在Hadoop上的开源数据仓库基础设施,通过Hive可以很容易的进行数据的ETL,对数据进行结构化处理,并对Hadoop上大数据文件进行查询和处理等. Hive提供了一种简单的类似SQL的查询语言-HiveQL,这为熟悉SQL语言的用户

大数据好学习吗?如何快速掌握大数据开发技能

大数据好学习吗?如何快速掌握大数据开发技能?经常被学员问到:大数据好学吗?想学大数据怕学不会等问题.我想说的是,大数据在当下是个非常热门的话题,大数据在深刻的影响着这个世界,在促进传统行业升级改造.引领新兴产业和新兴应用蓬勃发展.提升社会运行和管理效率等方面,大数据正引发新一轮革命.大数据是时代潮流,如果学一下就会了,那大数据行业现在恐怕已经被挤破门槛了吧,想学大数据还是得下苦功夫才行. 想学大数据,先把这几个技能学会再说: Apache Hive2.1 Hive是建立在Hadoop上的数据仓库