zoukankan      html  css  js  c++  java
  • 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 != '点评实验室';
    
  • 相关阅读:
    python模块
    Django基础
    Python __str__(self)和__unicode__(self)
    Redis基本操作
    测试面试宝典
    h5页面的测试方式
    selenium IDE的使用流程
    如何安装chrome扩展程序--selenium IDE
    Selenium 中 强制等待、显示等待、隐式等待的区别
    Selenium+Python 自动化 之八种元素定位方法
  • 原文地址:https://www.cnblogs.com/unnunique/p/9475637.html
Copyright © 2011-2022 走看看