1.4.3.3 Hive常用需知

2020-04-05  本文已影响0人  寒暄_HX

总目录: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参数。

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)

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)

常用操作

常用配置

  <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
...
日志
上一篇 下一篇

猜你喜欢

热点阅读