美文网首页
hive建表语句相关

hive建表语句相关

作者: 夜空最亮的9星 | 来源:发表于2018-08-07 23:05 被阅读59次

建表——明细宽表 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);

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

分步:
--抽取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; 

--抽取转换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;

以上语句可以改写成:

insert into table ods_weblog_detail partition(datestr='20130918')
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 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;


show partitions ods_weblog_detail;

数据导入

hdfs dfs -mkdir -p /weblog/preprocessed
hdfs dfs -mkdir -p /weblog/clickstream/pageviews
hdfs dfs -mkdir -p /weblog/clickstream/visits
hdfs dfs -mkdir -p /weblog/dim_time

hdfs dfs -put part-m-00000 /weblog/preprocessed
hdfs dfs -put part-r-00000 /weblog/clickstream/pageviews
hdfs dfs -put part-r-00000 /weblog/clickstream/visits
hdfs dfs -put dim_time_dat.txt /weblog/dim_time

set hive.exec.mode.local.auto=true;

---------------------

导入清洗结果数据到贴源数据表ods_weblog_origin

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;
---------------------------------------------------------------------------
导入点击流模型pageviews数据到ods_click_pageviews表

load data inpath '/weblog/clickstream/pageviews' overwrite into table ods_click_pageviews partition(datestr='20130918');
select count(*) from ods_click_pageviews;
-----------------------------------------------------------------------------
导入点击流模型visit数据到ods_click_stream_visit表

load data inpath '/weblog/clickstream/visits' overwrite into table ods_click_stream_visit partition(datestr='20130918');

----------------------------------------------------------------------------------------------------------------------

相关文章

  • Hive2:Hive SQL实践

    hive建表语句: 1.建内部表 hive (badou)> create table udata(userid ...

  • odps 表数据同步到hive仓库

    1.复制建表语句。做适当修改,把字段类型换成hive支持的类型。启动hive,粘贴建表 分区表例子 CREATET...

  • hive基本操作之一

    1.hive表中的基本数据类型 2,hive创建分区表 2.1内部表 建表语句: create table...

  • hive-入门

    hive脚本执行: hive建表语句: 创建一个文件并上传到hdfs: 查看表中的数据: 以上创建的表都是内部表,...

  • hive建表语句相关

    建表——明细宽表 ods_weblog_detail 通过查询插入数据到明细宽表 ods_weblog_deta...

  • hive中常用命令(建表、删表等)

    hive中常用命令(建表、删表等) 1.hive中的语句使用英文;结尾 2.进入数据库 use test_db; ...

  • hive基础语法

    目录 Hive安装和启动 Hive表操作-分区表 Hive表操作-复杂类型操作 Hive 查询语句 Zepplin...

  • hive集群迁移

    一、主要任务 1、建立hive表2、建立分区3、验证数据4、配置调度任务5、校验任务 二、hive建表语句 获取所...

  • hive进阶学习

    创建hive表常用语句: 修改hive表名称: 内部表 vs 外部表: 创建分区表以及补充操作: hive中查询介...

  • 解决 hive 建表注释中文乱码问题

    有时在 hive 中创建表之后,在查看表结构(describe TABLE_NAME)或者建表语句(show cr...

网友评论

      本文标题:hive建表语句相关

      本文链接:https://www.haomeiwen.com/subject/kymzvftx.html