zoukankan      html  css  js  c++  java
  • hadoop中hive常用的交互式操作

    hive的帮助命令:

    [hadoop@master tmp]$ hive -help
    usage: hive
     -d,--define <key=value>          Variable substitution to apply to Hive
                                      commands. e.g. -d A=B or --define A=B
        --database <databasename>     Specify the database to use
     -e <quoted-query-string>         SQL from command line
     -f <filename>                    SQL from files
     -H,--help                        Print help information
        --hiveconf <property=value>   Use value for given property
        --hivevar <key=value>         Variable substitution to apply to Hive
                                      commands. e.g. --hivevar A=B
     -i <filename>                    Initialization SQL file
     -S,--silent                      Silent mode in interactive shell
     -v,--verbose                     Verbose mode (echo executed SQL to the
                                      console)


    *hive  -e  --不进入交互式,直接执行

    [hadoop@master tmp]$ hive -e "select * from db_hive.u2;"
    Logging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: true
    OK
    u2.id   u2.name u2.age  u2.month        u2.day
    1       xm1     16      9       14
    2       xm2     18      9       14
    3       xm3     22      9       14
    4       xh4     20      9       14
    5       xh5     22      9       14
    6       xh6     23      9       14
    7       xh7     25      9       14
    8       xh8     28      9       14
    9       xh9     32      9       14
    Time taken: 5.155 seconds, Fetched: 9 row(s


    *hive   -f    <filename>
       先准备一个文件:hivef.sql

    [hadoop@master tmp]$ more hivef.sql
    select * from db_hive.u2;

     hive -f hivef.sql

    [hadoop@master tmp]$  hive -f hivef.sql
    
    Logging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: true
    OK
    u2.id   u2.name u2.age  u2.month        u2.day
    1       xm1     16      9       14
    2       xm2     18      9       14
    3       xm3     22      9       14
    4       xh4     20      9       14
    5       xh5     22      9       14
    6       xh6     23      9       14
    7       xh7     25      9       14
    8       xh8     28      9       14
    9       xh9     32      9       14
    Time taken: 5.398 seconds, Fetched: 9 row(s)

    还可以重定向到文件中:

    [hadoop@master tmp]$ hive -f hivef.sql>hive_result.txt
    
    Logging initialized using configuration in file:/home/hadoop/hive/conf/hive-log4j2.properties Async: true
    OK
    Time taken: 5.224 seconds, Fetched: 9 row(s)

    查看文件:

    [hadoop@master tmp]$ ls -rlt
    -rw-rw-r--.  1 hadoop hadoop       26 Apr  2 23:38 hivef.sql
    -rw-rw-r--.  1 hadoop hadoop      163 Apr  2 23:49 hive_result.txt
    [hadoop@master tmp]$ more hive_result.txt 
    u2.id   u2.name u2.age  u2.month        u2.day
    1       xm1     16      9       14
    2       xm2     18      9       14
    3       xm3     22      9       14
    4       xh4     20      9       14
    5       xh5     22      9       14
    6       xh6     23      9       14
    7       xh7     25      9       14
    8       xh8     28      9       14
    9       xh9     32      9       14
    


    hive -i <filename>     与用户udf相互使用

  • 相关阅读:
    Java中如何解决double和float精度不准的问题
    Linux防火墙Firewall和Iptables的使用
    yum 彻底删除nodejs,重新安装
    hbase集群搭建参考资料
    10分钟教你打造一个微信语音点歌系统
    微信公众平台向特定用户推送消息
    圆角与半角互相转换
    Swagger简单介绍
    测试通过!为何线上还有很多BUG?实践中的质量控制
    AXURE插件在 Chrome 浏览器中用不了怎么办?
  • 原文地址:https://www.cnblogs.com/hello-wei/p/10646230.html
Copyright © 2011-2022 走看看