美文网首页
1.4.3.3 Hive常用需知

1.4.3.3 Hive常用需知

作者: 寒暄_HX | 来源:发表于2020-04-05 08:43 被阅读0次

    总目录:https://www.jianshu.com/p/e406a9bc93a9

    Hadoop - 子目录:https://www.jianshu.com/p/9428e443b7fd

    常用命令行交互命令

    [root@master ~] hive -h
    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)
    

    我们主要理解 -e和-f参数。

    • -e

    SQL from command line
    命令行中的SQL

    本质上是在命令行中执行SQL语句。

    [root@master ~]# hive -e "select * from stu;"
    Logging initialized using configuration in jar:file:/usr/hdk/hive/lib/hive-common-2.3.6.jar!/hive-log4j2.properties Async: true
    OK
    1   zhangsan
    2   lisi
    3   wangwu
    4   liuniu
    5   zhaoqi
    1   zhangsan
    2   lisi
    3   wangwu
    4   liuniu
    5   zhaoqi
    Time taken: 11.535 seconds, Fetched: 10 row(s)
    
    • -f

    SQL from files
    文件中的SQL

    用来执行SQL文件。

    [root@master usr] cat cs.sql 
    select * from stu;
    [root@master usr] hive -f cs.sql 
    Logging initialized using configuration in jar:file:/usr/hdk/hive/lib/hive-common-2.3.6.jar!/hive-log4j2.properties Async: true
    OK
    1   zhangsan
    2   lisi
    3   wangwu
    4   liuniu
    5   zhaoqi
    1   zhangsan
    2   lisi
    3   wangwu
    4   liuniu
    5   zhaoqi
    Time taken: 11.204 seconds, Fetched: 10 row(s)
    

    常用操作

    • 在hive客户端内查看hdfs文件目录
      dfs -ls /

      查看hdfs
    • 在hive客户端内查看本地文件目录
      ! ls /usr/hdk

      查看本地
    • 在hive客户端内查看历史命令
      1.进入当前用户的家目录
      2.查看.hivehistory文件


      查看历史命令

    常用配置

    • 在客户端上显示当前库与字段名
      修改配置如下,第一个配置是列名,第二个是数据库名。
      <property>
        <name>hive.cli.print.header</name>
        <value>true</value>
        <description>Whether to print the names of the columns in query output.</description>
      </property>
      <property>
        <name>hive.cli.print.current.db</name>
        <value>true</value>
        <description>Whether to include the current database in the Hive prompt.</description>
      </property>
    
    效果
    • 修改日志存放目录
    [root@master conf] cp hive-log4j2.properties.template hive-log4j2.properties
    [root@master conf] vi hive-log4j2.properties
    [root@master conf] cat hive-log4j2.properties
    ...
    # list of properties
    property.hive.log.level = INFO
    property.hive.root.logger = DRFA
    property.hive.log.dir = /usr/hdk/hive/logs   #修改这个配置
    property.hive.log.file = hive.log
    property.hive.perflogger.log.level = INFO
    ...
    
    日志

    相关文章

      网友评论

          本文标题:1.4.3.3 Hive常用需知

          本文链接:https://www.haomeiwen.com/subject/stejphtx.html