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 的标志也不 ...
随机推荐
- tomcat添加crt证书
使用keytool生成证书苹果手机添加后提示未验证,可以使用Apache的openssl生成证书导入到tomcat中. 使用Apache 生成证书:openssl genrsa 4096 > s ...
- JS中的加号+运算符详解
加号+运算符 在 JavaScript 中,加法的规则其实很简单,只有两种情况: 把数字和数字相加 把字符串和字符串相加 所有其他类型的值都会被自动转换成这两种类型的值. 为了能够弄明白这种隐式转换是 ...
- 【BZOJ4245】[ONTAK2015]OR-XOR 贪心
[BZOJ4245][ONTAK2015]OR-XOR Description 给定一个长度为n的序列a[1],a[2],...,a[n],请将它划分为m段连续的区间,设第i段的费用c[i]为该段内所 ...
- 160818、CSS页面布局笔记
居中布局 水平居中 父元素和子元素的宽度都未知 inline-block + text-ailgn .child{display:inline-block;} .parent{text-align ...
- 前台传递给后台的JSON字符串中的引号 “” 在JAVA后台被转义为 "
前台传递给后台的JSON字符串中的引号 "" 在JAVA后台被转义为 " 1.问题: 前台数据,JSON字符串带有引号 "" ,数据被传递到后台 ...
- Centos7安装dubbo管理控制台
1.下载dubbo源代码 wget https://github.com/apache/incubator-dubbo/archive/2.5.x.zip 2.进入dubbo-admin目录下 cd ...
- 【题解】Journeys(线段树优化连边)
[#3073. Pa2011]Journeys (线段树优化连边) 这张图太直观了,直接讲透了线段树优化连边的原理和正确性. 考虑建立两颗线段树,一颗是外向树,一颗是内向树,相当于网络流建模一样,我们 ...
- 阿里云短信验证解决方案(java版)(redis存储)
最近搞了一个互联网项目的注册,需要写一个手机号验证(由于之前没有轮子,只能自己摸索了); 1:基本思路: 1>购买了阿里云短信服务->下载阿里云短信发送demo(java版); 2> ...
- excel同时冻结首行和首列怎么操作
之前ytkah只知道excel可以冻结首行或首列,但还不清楚如何同时冻结excel首行和首列,后面看到小C的报表,问了他才明白怎么操作. 首先,我们先把选中B2单元格,点击导航菜单的“视图” - “冻 ...
- ALE和IDocs
转自:http://blog.163.com/shenshengqge@126/blog/static/820512902011101152518635/ 作为目前ERP市场上最为领先的应用系统之一, ...