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 的标志也不 ...
随机推荐
- es站内站内搜索笔记(一)
es站内站内搜索笔记(一) 第一节: 概述 使用elasticsearch进行网站搜索,es是当下最流行的分布式的搜索引擎及大数据分析的中间件,搜房网的主要功能:强大的搜索框,与百度地图相结合,实现地 ...
- 【转】NPOI自定义单元格背景颜色
经常在NPOI群里聊天时发现有人在问NPOI设置单元格背景颜色的问题,而Tony Qu大神的博客里没有相关教程,刚好最近在做项目时研究了一下这一块,在这里总结一下. 在NPOI中默认的颜色类是HSSF ...
- ehcache 配置持久化到硬盘(四)
Ehcache默认配置的话 为了提高效率,所以有一部分缓存是在内存中,然后达到配置的内存对象总量,则才根据策略持久化到硬盘中,这里是有一个问题的,假如系统突然中断运行 那内存中的那些缓存,直接被释放掉 ...
- 如何枚举 Windows 顶级桌面窗口?
bool is_top_level_window(HWND hwnd) { if (!IsWindow(hwnd)) return false; DWORD dw_style = GetWindowL ...
- ffmpeg参数使用说明1
1. ffmpeg.exe -i F:闪客之家闪客之歌.mp3 -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 f:11.flv 2. ffmpeg ...
- 虚拟研讨会:如何设计好的RESTful API(转)
原文:虚拟研讨会:如何设计好的RESTful API? REST架构风格最初由Roy T. Fielding(HTTP/1.1协议专家组负责人)在其2000年的博士学位论文中提出.HTTP就是该架构风 ...
- linux虚拟机能ping通windows主机,windows主机ping不通linux虚拟机的解决办法
分三步: 1.虚拟机网络连接方式选择Nat
- ubuntu常见错误--Could not get lock /var/lib/dpkg/lock解决(转)
通过终端安装程序sudo apt-get install xxx时出错: E: Could not get lock /var/lib/dpkg/lock - open (11: Resource t ...
- C#编写图书列表winform
Book.cs文件 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
- python常用模块——logger模块
python的logging模块提供了通用的日志系统,熟练使用logging模块可以方便开发者开发第三方模块或者是自己的python应用. python使用logging模块记录日志涉及四个主要的类: ...