【Hive】SQL使用

  1. 强制删除一个database
    DROP DATABASE IF EXISTS dbname CASCADE;
  2. 删除一个table
    drop table if exists xxxx
  3. 分区查询
    show partitions xxx
  4. Hive复杂查询
    • select * from pic_collection where pic_collection.uid in (select uid from pic_collection group by uid having count(*) > 1)
    • insert overwrite local directory ‘/var/lib/hadoop-hdfs/chenguolin/pic_gateway/url’ select ori_pic_url from pic_collection where pic_collection.uid in (select uid from pic_collection group by uid having count(*) > 1);
  5. hive表添加字段
    ALTER TABLE sdk_report_upstream ADD COLUMNS (push_ping_packet_loss_cnt int, push_ping_succ_cnt int, push_ping_total_rtt double);
  6. Hive Map查询
    • select version, response_code from chaos_log where date=2017121817 and version=6850 and size(response_code) > 0 limit 10;
    • select version, response_code from chaos_log where date=2017121817 and version=6850 and size(response_code) > 0 and response_code[‘0’] = ‘403’
  7. Hive查询指定特殊的分隔符
    • insert overwrite local directory ‘/var/lib/hadoop-hdfs/chenguolin/pic_gateway/url’ row format delimited fields terminated by ‘\t’ COLLECTION ITEMS TERMINATED BY ‘,’ MAP KEYS TERMINATED BY ‘:’ select ori_pic_url from pic_collection where pic_collection.uid in (select uid from pic_collection group by uid having count(*) > 1);
  8. Hive distinct使用
    • select day, stream_type, count(distinct id) from media_quality.sdk_report_upstream where date >= 2017122700 and date <= 2017123123 group by stream_type, day;
上一篇:img元素srcset属性浅析


下一篇:JS实现自动轮播图效果(js案例)