Hive的Shell操作

一、Hive的命令行

1、Hive支持的一些命令

Command Description

quit Use quit or exit to leave the interactive shell.

set key=value Use this to set value of particular configuration variable. One thing to note here is that if you misspell the variable name, cli will not show an error.

set This will print a list of configuration variables that are overridden by user or hive.

set -v This will print all hadoop and hive configuration variables.

add FILE [file] [file]* Adds a file to the list of resources

add jar jarname

list FILE list all the files added to the distributed cache

list FILE [file]* Check if given resources are already added to distributed cache

! [cmd] Executes a shell command from the hive shell

dfs [dfs cmd] Executes a dfs command from the hive shell

[query] Executes a hive query and prints results to standard out

source FILE Used to execute a script file inside the CLI. 在hive的客户端执行一个hql脚本

2、语法结构

hive [-hiveconf x=y]* [<-i filename>]* [<-f filename>|<-e query-string>] [-S]

说明:

1、-i 从文件初始化 HQL

2、-e 从命令行执行指定的 HQL

3、-f 执行 HQL 脚本

4、-v 输出执行的 HQL 语句到控制台

5、-p connect to Hive Server on port number

6、-hiveconf x=y(Use this to set hive/hadoop configuration variables)

7、-S:表示以不打印日志的形式执行命名操作

3、示例

(1)运行一个查询

[qyl@qyl01 ~]$ hive -e "select * from cookie.cookie1;"

(2)运行一个文件

 编写hive.sql文件

运行编写的文件

(3)运行参数文件

从配置文件启动hive,并加载配置文件当中的配置参数

二、Hive的参数配置方式

1、Hive的参数配置大全

    https://cwiki.apache.org/confluence/display/Hive/Configuration+Properties

2、Hive参数设置方式

    开发Hive应用时,不可避免的需要设定Hive的参数,设定Hive的参数可以调优HQL代码的执行效率,或帮助定位解决问题。然而实践中经常晕倒的一个问题是,为什么设定的参数没有起作用?这通常是错误的设定方式导致的。

   1、配置文件(全局有效)

   2、命令行参数(对Hive启动实例有效)

   3、参数声明(对hive的连接session有效)

(1)配置文件

            Hive 的配置文件包括:

              A. 用户自定义配置文件:$HIVE_CONF_DIR/hive-site.xml

              B. 默认配置文件:$HIVE_CONF_DIR/hive-default.xml

                用户自定义配置会覆盖默认配置。

              另外,Hive 也会读入 Hadoop 的配置,因为 Hive 是作为 Hadoop 的客户端启动的,Hive 的配 置会覆盖 Hadoop 的配置。

配置文件的设定对本机启动的所有 Hive 进程都有效。

(2)命令行参数

         启动 Hive(客户端或 Server 方式)时,可以在命令行添加-hiveconf param=value 来设定参数,例如:

这一设定对本次启动的 session(对于 server 方式启动,则是所有请求的 session)有效。

(3)参数声明

   可以在 HQL 中使用 SET 关键字设定参数,例如:

猜你喜欢

转载自blog.csdn.net/weixin_43823423/article/details/86655917
今日推荐