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
    
  • 相关阅读:
    【初学EXT】布局练习
    创建型模式总结(补充UML类图)
    数据库基本概念总结
    Word2010操作技巧总结
    VMWare虚拟机磁盘压缩和上网总结
    第一次用word2010发布文章到博客园记
    设计模式学习总结一原则及创建型模式
    为什么要开始写blog?
    Delphi异常处理总结
    设计模式总结之行为型模式
  • 原文地址:https://www.cnblogs.com/hannahzhao/p/11762691.html
Copyright © 2011-2022 走看看