• hive 进阶笔记


     
    -- mysql方式
    create table account_channel(account_ String,channel_ String)  as select 
    a.account,b.channel from register a join `install` b on a.device = b.device
    
    -- hive方式
    create table account_channel ROW FORMAT DELIMITED FIELDS TERMINATED BY '^' STORED AS TEXTFILE  select  distinct a.account,b.channel from register a join install b on a.device = b.device;
    以覆盖的方式添加数据
    INSERT OVERWRITE account_channel2  IF NOT EXISTS select  distinct a.account,b.channel from register a join install b on a.device = b.device;
    INSERT into account_channel   select  distinct a.account,b.channel from register a join install b on a.device = b.device;

    场景描述,在hive中需要一张中间表,比如一个已知设备库,但是随着用户的增加,设备库是要数据量谁要增加的,(insert新的数据,保留已有的数据).然后在业务中使用

    解决方案,第一次create select ,之后每次都 insert into select ,这是select 的就很关键,这个select 需要 查询到已知设备库中没有的数据.这样就能实现设备库的更新

     insert into select 的缺点是不能重复执行,重复执行机会产生重复数据.insert overwrite 不会产生重复数据

    当表 为空表的时候mysql中count的结果是null但是在hive中count的结果是0

    在使用 group by 的时候有时会觉得需要一个循环才能实现,此时可以考虑将需要循环的字段也加入group by 中,然后再加上order by 就和循环的效果一样了.

    有一个约定就是在group by 后面要加上使用聚合函数的字段之外的所有字段.这个约束在mysql 中是可以不遵守的.但是按理来说是必须要遵守的

    hive 的分区字段可以在from之前出现,可以在join时使用.

  • 相关阅读:
    CSZ CMS 1.2.7 xss分析与复现
    蚁剑改造过WAF系列(一)
    代理池
    二维码劫持案例分析
    入门KKCMS代码审计
    Xposed+XServer无需脱壳抓取加密包
    通达OA前台任意用户登录分析
    ATutor学习内容管理系统任意文件上传漏洞(CVE-2019-12169)分析
    调试System.AggregateException-即使在异步代码中也是如此
    关于System.Exception
  • 原文地址:https://www.cnblogs.com/rocky-AGE-24/p/7435836.html
Copyright © 2020-2023  润新知