hive 学习系列之七 hive 常用数据清洗函数

1,case when 的利用,清洗诸如评分等的内容,用例如下。

case 
   when new.comment_grade = '五星商户' then 50
   when new.comment_grade = '准五星商户' then 45
   when new.comment_grade = '四星商户' then 40
   when new.comment_grade = '准四星商户' then 35
   when new.comment_grade = '三星商户' then 30
   when new.comment_grade = '准三星商户' then 25
   when new.comment_grade = '二星商户' then 20
   when new.comment_grade = '准二星商户' then 15
   when new.comment_grade = '一星商户' then 10
   when new.comment_grade = '准一星商户' then 5
   when new.comment_grade = '该商户暂无星级' then 0
   when new.comment_grade is NULL then old.comment_grade
   else new.comment_grade
END as `new.comment_grade`,

2, 替换字符串中的一些内容。

regexp_replace(new.avg_price, '-', '')
替换 avg_price 中的中划线。

3, 字符串切分函数

split(a.tag_flag, '>')[1],
具体例子:
select split('a,b', ',')[0]  ===> 结果 a

4, 字符串拼接函数

SELECT concat('1', '2');     ====》 结果 12
SELECT concat('1', '2', '3');   ===> 结果 123 


### 5, 去除字符串两端空格

trim(a.city)


6, 使用left join 或者 right join 补全数据

例如根据两张表,其中一张表格table2含有省份和城市的信息,
其中一张表table1只有城市信息,需要补全table1 中的省份信息,可以像如下做法:
select 
    a.name,
    b.province,
    a.city
from table1 a left join table2 b on  a.city = b.city;

7,其他:清除一些不符合条件的数据

可以使用等值判断来处理数据
清除一些不符合条件的数据。
INSERT OVERWRITE table ods.js_beauty_tmp
SELECT *
from ods.js_beauty_tmp
WHERE map_lat != ''
AND map_lng != ''
AND map_lat IS NOT NULL
AND map_lng IS NOT NULL
AND map_lat != 0
AND map_lng != 0
AND map_lat not like '-%'
AND map_lng not like '-%'
and city != '其他城市'
and city != '点评实验室';

转载于:https://www.cnblogs.com/unnunique/p/9475637.html

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值