zoukankan      html  css  js  c++  java
  • hive查询语句入门(hive DDL)

    hive DDL

    • 启动hadoop
    /apps/hadoop/sbin/start-all.sh
    
    • 开启MySQL库,用于存放hive的元数据
    sudo service mysql start
    
    • 启动hive
    hive
    
    • 在/data/hive3下下载数据库数据
    mkdir /data/hive3
    cd data/hive3
    wget http://192.168.1.100:60000/allfiles/hive3/buyer_log  
    wget http://192.168.1.100:60000/allfiles/hive3/buyer_favorite 
    
    • 在hive中创建数据库并以' '为分隔符
    create table buyer_log(id string,buyer_id string,dt string,ip string,opt_type string) row format delimited fields terminated by '	' stored as textfile;
    
    • 将/data/hive3下的数据导入到hive中
    load data local inpath '/data/hive3/buyer_log' into table buyer_log;
    load data local inpath '/data/hive3/buyer_favorite' into table buyer_favorite;
    
    • 普通查询
    select * from buyer_log limit 10;
    
    • 别名查询
    select b.id,b.ip from buyer_log b limit 10;
    
    • 限定查询
    select buyer_id from buyer_log where opt_type=1 limit 10;
    
    • 两表或多表联合查询
    select l.dt,f.goods_id from buyer_log l,buyer_favorite f where l.buyer_id=f.buyer_id limit 10;
    
    • 多表插入
    create table buyer_log1 like buyer_log;
    create table buyer_log2 like buyer_log;
    from buyer_log insert overwrite table buyer_log1 select * 
    insert overwrite table buyer_log2 select *;
    
    • 多目录输出文件
    from buyer_log
    insert overwrite local directory '/data/hive3/out' select *;
    insert overwrite local directory '/data/hive3/out1' select *;
    
    • 使用本地shell脚本调用hive查询语句
    #!/bin/bash
    cd /apps/hive/sbin;
    hive -e 'show tables;'
    
    chmod +x sh1
    ./sh1
    
  • 相关阅读:
    【2019/3/23】周进度报告
    第十周总结
    程序员修炼之道-从小工到专家阅读笔记01
    第九周总结
    用户模板和用户场景
    一维数组最大子数组续
    程序员的自我修养阅读笔记03
    第八周总结
    NABCD项目分析
    第七周总结
  • 原文地址:https://www.cnblogs.com/hannahzhao/p/11762691.html
Copyright © 2011-2022 走看看