hive学习8(小案例1练习)
创建数据库
hive> create database feigu;
hive> use feigu;
创建表
- stg_job表
drop table if exists stg_job;
create table if not exists stg_job(
web_id string comment 'web id',
web_type string comment 'web type',
job_url string comment 'job url',
job_name string comment 'job name',
job_location string comment 'job location',
job_desc string comment 'job desc',
edu string comment 'education',
gender string comment 'gender',
language string comment 'language',
major string comment 'major',
work_year string comment 'work years',
salary string comment 'salary',
company_name string comment 'company name',
company_desc string comment 'company desc',
company_address string comment 'company address',
company_worktype string comment 'company worktype',
company_scale string comment 'company scale',
company_prop string comment 'company property',
company_website string comment 'company_website',
curl_timestamp string comment 'curl timestamp'
)
comment 'all flat data from webpage'
partitioned by (`pt` string comment 'job post date ')
row format delimited
fields terminated by '\001'
null defined as ''
stored as textfile;
- s_job表(与stg_job相同的表结构)
create table s_job like stg_job;
- stg_news表
drop table if exists stg_news;
create table if not exists stg_news(
mysql_newsid string,
news_title string,
content string,
create_time string
)
comment 'all flat thread from Dz'
partitioned by (`pt` string )
row format delimited
fields terminated by '\001'
null defined as ''
stored as textfile;
- dm_job表
drop table if exists dm_job;
create table if not exists dm_job(
web_id string comment 'web id',
web_type string comment 'web type',
job_url string comment 'job url',
job_name string comment 'job name',
job_location string comment 'job location',
job_desc string comment 'job desc',
edu string comment 'education',
gender string comment 'gender',
language string comment 'language',
major string comment 'major',
work_year string comment 'work years',
salary string comment 'salary',
job_date string comment 'job date',
company_name string comment 'company name',
company_desc string comment 'company desc',
company_address string comment 'company address',
company_worktype string comment 'company worktype',
company_scale string comment 'company scale',
company_prop string comment 'company property',
company_website string comment 'company_website',
curl_timestamp string comment 'curl timestamp',
vip_flg string
)
comment 'compute vip '
partitioned by (`pt` string)
row format delimited
fields terminated by '\001'
null defined as ''
stored as sequencefile;
- dim_edu表
drop table if exists dim_edu;
create table if not exists dim_edu(
web_type string,
job_name string,
company_name string,
edu_detail string,
edu_type string
)
comment 'edu dimision'
partitioned by (`pt` string)
row format delimited
fields terminated by '\001'
null defined as ''
stored as sequencefile;
- dim_workyear表
drop table if exists dim_workyear;
create table if not exists dim_workyear(
web_type string,
job_name string,
company_name string,
workyear_detail string,
workyear_type string
)
comment 'work years'
partitioned by (`pt` string)
row format delimited
fields terminated by '\001'
null defined as ''
stored as sequencefile;
- dim_joblocation表
drop table if exists dim_joblocation;
create table if not exists dim_joblocation(
web_type string,
job_name string,
company_name string,
joblocation_detail string,
joblocation_type string
)
comment 'job location'
partitioned by (`pt` string)
row format delimited
fields terminated by '\001'
null defined as ''
stored as sequencefile;
- dim_salary表
drop table if exists dim_salary;
create table if not exists dim_salary(
web_type string,
job_name string,
company_name string,
salary_detail string,
salary_type string
)
comment 'job salary'
partitioned by (`pt` string)
row format delimited
fields terminated by '\001'
null defined as ''
stored as sequencefile;
数据导入
将爬虫爬取的职位表信息导入到stg_job表中
hive> load data local inpath '/home/data/daily/20150501/51job1.dat'
> overwrite into table stg_job
> partition (pt='20150501');
hive数据清洗(ETL)
- 数据项为空:网页抓取下来的数据可能是空的需要剔除
- 检索结果不一致:编码或命名差异,例如品牌=耐克,商品品牌=耐克
- 噪声:包含错误或者异常值,如salary='-100'
数据预处理分为数据清理,数据变换,数据集成
对job_location(工作地点), edu(学历), work_year(工作年限),salary(薪资范围)4列数据的空值进行转换
hive> insert overwrite table s_job partition (pt)
> select
> web_id,web_type,job_url,job_name,
> case when job_location is null or trim(job_location) = "" then "--" else job_location end
> job_location,
> job_desc,
> case when edu is null or trim(edu) = "" then "--" else edu end
> edu,
> gender,language,major,
> case when work_year is null or trim(work_year) = "" then "--" else work_year end
> work_year,
> case when salary is null or trim(salary) = "" then "--" else salary end
> salary,
> company_name,company_desc,company_address,
> company_worktype,company_scale,company_prop,company_website,curl_timestamp,
> pt from stg_job
> where pt="20150501";
代码注释
- insert overwrite table...partition (...) select 将查询结构集写入另一个表中
- partition(pt):在目标表中使用了动态分区,会在s_job表中自动创建分区
- overwrite会先删除s_job中pt='20150501'分区的数据,避免相同分区下的数据重复导入
hive提取维度信息
抽取“学历要求”维度信息插入到学历维度表
hive> insert into table dim_edu partition (pt)
> select web_type,job_name,company_name,
> edu as edu_detail,
> case
> when (edu like '%大专%' = true or edu like '%专科%' = true) then 'B1'
> when (edu like '%本科%' = true) then 'B2'
> when (edu like '%硕士%' = true or edu like '%研究生%' = true) then 'B3'
> else 'B9'
> end
> as edu_type,
> pt
> from s_job where s_job.pt='20150501';
抽取“工作地点”维度信息插入到工作地点维度表
hive> insert into table dim_joblocation partition (pt)
> select web_type,job_name,company_name,
> job_location as joblocation_detail,
> case
> when (job_location like '%北京%' = true) then 'A1'
> when (job_location like '%上海%' = true) then 'A2'
> when (job_location like '%广州%' = true) then 'A3'
> when (job_location like '%深圳%' = true) then 'A4'
> else 'A9'
> end
> as joblocation_type,
> pt
> from s_job where s_job.pt='20150501';
hive学习8(小案例1练习)的更多相关文章
- hive学习(五) 应用案例
1.实现struct数据结构例子 1.1创建student表 create table student( id int, info struct<name:string,age:int> ...
- Hive学习 系列博客
原 Hive作业优化 原 Hive学习六:HIVE日志分析(用户画像) 原 Hive学习五--日志案例分析 原 Hive学习三 原 Hive学习二 原 Hive学习一 博客来源,https://blo ...
- Vue小案例 之 商品管理------学习过滤器 使用过滤器处理日期的格式
代码学习过滤器 过滤器介绍:过滤模型数据,在数据显示前做预处理操作: 内置过滤器:在1.x中,Vue提供了内置过滤器,但是在2.x中已经完全废除: 解决办法: (1)使用第三方库来替代1.x中的内置过 ...
- JavaScript_DOM学习篇_图片切换小案例
今天开始学习DOM操作,下面写一个小案例来巩固下知识点. DOM: document object model (文档对象模型) 根据id获取页面元素 : 如: var xx = document.g ...
- [jQuery学习系列六]6-jQuery实际操作小案例
前言最后在这里po上jQuery的几个小案例. Jquery例子1_占位符使用需求: 点击第一个按钮后 自动去check 后面是否有按钮没有选中, 如有则提示错误消息. <html> &l ...
- 【大数据】Hive学习笔记
第1章 Hive基本概念 1.1 什么是Hive Hive:由Facebook开源用于解决海量结构化日志的数据统计. Hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张表, ...
- hive学习
大数据的仓库Hive学习 10期-崔晓光 2016-06-20 大数据 hadoop 10原文链接 我们接着之前学习的大数据来学习.之前说到了NoSql的HBase数据库以及Hadoop中 ...
- Hive学习路线图(转)
Hadoophivehqlroadmap学习路线图 1 Comment Hive学习路线图 Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Hadoop, Hive, Pig ...
- 【转】Hive学习路线图
原文博客出自于:http://blog.fens.me/hadoop-hive-roadmap/ 感谢! Hive学习路线图 Hadoop家族系列文章,主要介绍Hadoop家族产品,常用的项目包括Ha ...
- MVC 小案例 -- 信息管理
前几次更新博客都是每次周日晚上到周一,这次是周一晚上开始写,肯定也是有原因的!那就是我的 Tomact 忽然报错,无法启动,错误信息如下!同时我的 win10 也崩了,重启之后连 WIFI 的标志也不 ...
随机推荐
- joisino's travel
D - joisino's travel Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement T ...
- ST表(离线RMQ)
离线RAQ时,预处理为O(n*lgn),查询为O(1)的算法,比较有意思的一种算法 放个模板在这可以随时看 //ST表(离线) //预处理 O(n*lgn) , 查询 O(1) #include &l ...
- EasyGBS国标流媒体视频平台接入海康、大华、宇视的摄像机、硬盘录像机NVR、国标下级平台的方案
在上一篇<EasyNVR和EasyDSS云平台联手都不能解决的事情,只有国标GB28181能解决了>我们大致介绍了国标GB/T28181的使用场景,而且初步介绍了EasyGBS国标视频平台 ...
- 技术总结PHP+微信
ajax: //获取商品属性数据 function initGoodsAttr(){ $.ajax({ type: 'GET', url:"<?php ...
- 学习编译并运行C代码
以<UNIX网络编程>中的代码为例,学习如何编译并运行C代码. 根据 UNIX网络编程(第3版)环境搭建——使用MAC OSX10.10,能够成功运行 1.下载本书的头文件及示例源码原书地 ...
- Delphi运算符及优先级
单目运算符 (最高优先级) @ 取变量或函数的地址(返回一个指针) not 逻辑取反或按位取反 乘除及按位运算符 * 相乘或集合交集 / 浮点相除 div 整数相除 mod 取模 (整数相除的余数) ...
- php扩展redis链接失败,返回false
刚开始接触redis,发现一直返回false,其实只要关闭防火墙就可以连接成功了. 关闭selinux操作 方法1:修改grub.conf将参数selinux=1修改为等于selinux=0,这个 ...
- Python3.6全栈开发实例[018]
18.车牌区域划分, 现给出以下车牌.根据车牌的信息, 分析出各省的车牌持有量.(升级题) result = {} for car in cars: location = locals[car[0]] ...
- vue-cli 搭建项目
1.cnpm install -g vue-cli 2.vue -V(注意大写,查vue版本) 3.vue init webpack vue1(创建vue1目录) 4.cd vue1(定位到目录中) ...
- corethink功能模块探索开发(三)让这个模块可见
感觉corethink把thinkphp的思想复用到淋漓尽致. 1.把opencmf.php文件配置好了后台该模块的菜单就能在安装后自动读取(分析好父子关系,否则页面死循环,apache资源占用率10 ...