网络日志的Hive简单查询

测试数据

[root@master hive]# cat ./tmp_data/weblog.data
1c13c719fbfd87f49522f189413c6ba /gybfokxyojgtwrq.html   2012-05-10  21:17:32    169.65.197.63
e42fe5714cb4402f81e5dce8da1755  /hpipbodlxgt.html   2012-05-10  21:12:04    166.22.84.135
[root@master hive]# cat ./tmp_data/ip_to_country.txt 
169.65.197.63   United States
166.22.84.135   United Kingdom

建表语句

[root@master hive]# cat /opt/weblog.hive 
create external table weblog_entries
( md5 string,
url string,
request_date string,
request_time string,
ip string
)
row format delimited fields terminated by '\t'
lines terminated by '\n'
location '/data/hive/weblog';
[root@master hive]# cat /opt/ip_to_country.hive 
create table ip_to_country(
ip string,
country string
)
row format delimited fields terminated by '\t'
lines terminated by '\n'
location '/data/hive/ip_to_country';

加载数据

hive> load data local inpath './tmp_data/weblog.data' into table weblog_entries;
hive> load data local inpath './tmp_data/ip_to_country.txt' into table ip_to_country;

连接查询

hive> select wle.*, itc.country FROM weblog_entries wle join ip_to_country itc on wle.ip = itc.ip;

使用查询结果创建新表

hive> create table weblog_entries_with_url_length as select url, request_date, request_time, length(url) as url_length from weblog_entries;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,269评论 19 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,613评论 25 709
  • 是夜,牵着小糯米团子的手行走于河边,耳边有微微的凉风习习,眼前是万家的灯火⋯⋯ 若不去想前尘后世,此一刻,人生于我...
    清江月阅读 269评论 0 1
  • 第八章,投资者与市场波动 1.在任何一个几年的期限内,普通股组合几乎必然会发生价值的波动。应了解这些可能发生的情况...
    新兴市场的小逻辑阅读 593评论 0 2
  • 这是补六月十六号的 嗯 今天呢 在观看他们的大战 (⊙_⊙) 心中略有愧疚吧
    ABO_875b阅读 189评论 0 0