Hive客户端工具后续将使用Beeline 替代HiveCLI ,并且后续版本也会废弃掉HiveCLI 客户端工具,Beeline是 Hive 0.11版本引入的新命令行客户端工具,它是基于SQLLine CLI的JDBC客户端。

Beeline支持嵌入模式(embedded mode)和远程模式(remote mode)。在嵌入式模式下,运行嵌入式的Hive(类似Hive CLI),而远程模式可以通过Thrift连接到独立的HiveServer2进程上。从Hive 0.14版本开始,Beeline使用HiveServer2工作时,它也会从HiveServer2输出日志信息到STDERR。

1. beeline 的常用参数

Usage: java org.apache.hive.cli.beeline.BeeLine
-u <database url> the JDBC URL to connect to
-n <username> the username to connect as
-p <password> the password to connect as
-d <driver class> the driver class to use
-i <init file> script file for initialization
-e <query> query that should be executed
-f <exec file> script file that should be executed
-w (or) --password-file <password file> the password file to read password from
--hiveconf property=value Use value for given property
--hivevar name=value hive variable name and value
This is Hive specific settings in which variables
can be set at session level and referenced in Hive
commands or queries.
--color=[true/false] control whether color is used for display
--showHeader=[true/false] show column names in query results
--headerInterval=ROWS; the interval between which heades are displayed
--fastConnect=[true/false] skip building table/column list for tab-completion
--autoCommit=[true/false] enable/disable automatic transaction commit
--verbose=[true/false] show verbose error messages and debug info
--showWarnings=[true/false] display connection warnings
--showNestedErrs=[true/false] display nested errors
--numberFormat=[pattern] format numbers using DecimalFormat pattern
--force=[true/false] continue running script even after errors
--maxWidth=MAXWIDTH the maximum width of the terminal
--maxColumnWidth=MAXCOLWIDTH the maximum width to use when displaying columns
--silent=[true/false] be more silent
--autosave=[true/false] automatically save preferences
--outputformat=[table/vertical/csv2/tsv2/dsv/csv/tsv] format mode for result display
Note that csv, and tsv are deprecated - use csv2, tsv2 instead
--truncateTable=[true/false] truncate table column when it exceeds length
--delimiterForDSV=DELIMITER specify the delimiter for delimiter-separated values output format (default: |)
--isolation=LEVEL set the transaction isolation level
--nullemptystring=[true/false] set to true to get historic behavior of printing null as empty string
--addlocaldriverjar=DRIVERJARNAME Add driver jar file in the beeline client side
--addlocaldrivername=DRIVERNAME Add drvier name needs to be supported in the beeline client side
--help display this message
Beeline version 2.3.4.spark2 by Apache Hive

参数详解

选项

描述
-u <database URL>

用于JDBC URL连接。用例:beeline -u db_URL

-r

重新连接到最近使用过的URL(如果用户有预先使过的用的,用!connect生成URL,用!save 生成beeline.properties.file)。

用例: beeline -r  

Version: 2.1.0 (HIVE-13670)

-n <username>

连接时使用的用户名。用例: beeline -n valid_user

-p <password>

连接时使用的密码。用例: beeline -p valid_password      可选的密码模式: 从Hive 2.2.0开始参数-p选项是可选的。

用例 : beeline -p [valid_password]

如果密码不是在-p之后提供的,Beeline将在初始化连接时提示输入密码。当密码提供后Beeline会用它来初始化连接而不提示。

-d <driver class>

配置使用的驱动类  用例: beeline -d driver_class

-e <query>

应该执行的查询。查询语句两端用单引号和双引号。这个选项被使用多次。用例: beeline -e "query_string"
支持运行复杂的SQL语句,在一个语句中通过使用分号分隔。(HIVE-9877)
Bug fix (null pointer exception): 0.13.0(HIVE-5765)
Bug fix (--headerInterval not honored): 0.14.0  (HIVE-7647)
Bug fix (running -e in background): 1.3.0 and 2.0.0 (HIVE-6758); workaround available for earlier versions

-f <file>

需要被执行的脚本文件。用例: beeline -f filepath
Version: 0.12.0  (HIVE-4268)
注:如果脚本里面包含tabs,版本0.12.0中查询编译失败,这个bug已经在0.13.0版本修复了。(HIVE-6359).
Bug fix (running -f in background): 1.3.0 and 2.0.0 (HIVE-6758);  workaround available for earlier versions

-i (or) --init <file or files>

初始化需要的初始文件。用例: beeline -i /tmp/initfile
单个文件:Version: 0.14.0 (HIVE-6561)
多个文件:Version: 2.1.0 (HIVE-11336)

-w (or) --password-file <password file> 从文件中读取密码。Version: 1.2.0 (HIVE-7175)
-a (or) --authType <auth type> jdbc的认证类型是一个身份认证属性。Version: 0.13.0  (HIVE-5155)
 --property-file <file>

读取配置属性的文件用例: beeline --property-file /tmp/a

Version: 2.2.0 (HIVE-13964)

 --hiveconf property=value  为给定的配置属性赋值。 在hive.conf.restricted.list列表中的属性不能通过hiveconf的方式重置。 (see  Restricted List and Whitelist).

用例: beeline --hiveconf prop1=value1
Version: 0.13.0  (HIVE-6173)

 --hivevar name=value  Hive的变量名和变量值。这是一个Hive指定的设置,在这变量能够在会话级别被设置和被Hive命令和查询引用。

用例: beeline --hivevar var1=value1

 --color=[true/false]  制颜色是否被用来展示。默认是false 用例: beeline --color=true

(不支持分隔的值输出方式。See HIVE-9770)

 --showHeader=[true/false] 展示列名是否在查询结果中。默认是true。用例: beeline --showHeader=false 
 --headerInterval=ROWS

当输出为表格时,重新显示列头时他们之间的间隔,用行数计算。默认值为100 用例: beeline --headerInterval=50
(不支持分隔的值输出方式。See HIVE-9770)

 --fastConnect=[true/false]  连接时,跳过为HiveQL语法的tab键自动补全功能而构建所有表和列的清单,默认为true不构建该列表。 用例: beeline --fastConnect=false
--autoCommit=[true/false]   允许或者禁止自动事务执行。默认是false    用例: beeline --autoCommit=true
 --verbose=[true/false]  展示冗长的报错信息和调试信息(true)或者不展示(false),默认是false    用例: beeline --verbose=true
 --showWarnings=[true/false]  Default is false.连接时,在执行任意HiveQL命令后展示警告信息。默认是false。 用例: beeline --showWarnings=true
 --showDbInPrompt=[true/false]  在提示符里面展示当前数据库名字。默认是false。用例: beeline --showDbInPrompt=true

Version: 2.2.0 (HIVE-14123)

--showNestedErrs=[true/false] 

展示内部错误,默认是false。用例: beeline --showNestedErrs=true

 --numberFormat=[pattern]  用一个小数格式的模板来格式化数字。用例: beeline --numberFormat="#,###,##0.00"
--force=[true/false]   出错后继续运行脚本(true),或者不运行(false)。默认是false。用例: beeline--force=true
 --maxWidth=MAXWIDTH  当输出格式是表格时,在截断数据前展示的最大宽度。默认是查询时的终端的当前宽度,然后回到80。用例: beeline --maxWidth=150
 --maxColumnWidth=MAXCOLWIDTH  当输出是表格时,最大列宽,Hive 2.2.0以后默认是50,之前的版本是15。用例: beeline --maxColumnWidth=25
 --silent=[true/false]  是(true)否(false)减少展示的信息量。它也会停止展示HiveServer2(Hive 0.14及之后的版本)的查询和命令(Hive 1.2.0及之后的版本)日志信息,默认是false。用例: beeline --silent=true
 --autosave=[true/false]  自动保存参数选择(true)或者不保存(false)。默认是false。用例: beeline --autosave=true
 --outputformat=[table/vertical/csv/tsv/dsv/csv2/tsv2]  结果展示的模式。默认是表格。查阅下方的Separated-Value Output Formats获取更多信息和推荐选项。用例: beeline --outputformat=tsv

版本号: dsv/csv2/tsv2 added in 0.14.0 (HIVE-8615)

 --truncateTable=[true/false]  如果是true,那么当表格超出终端显示宽度时,截断表格的列在终端上展示。版本号: 0.14.0 (HIVE-6928)
 --delimiterForDSV= DELIMITER  用于输出格式中划分值的界定符。默认是‘|’      版本号: 0.14.0 (HIVE-7390)
 --isolation=LEVEL

设置事务隔离级别为TRANSACTION_READ_COMMITTED或者TRANSACTION_SERIALIZABLE.  可以查阅Java连接文档中“Field Detail”那一章节。

用例: beeline --isolation=TRANSACTION_SERIALIZABLE

 --nullemptystring=[true/false]  使用历史的打印空字符null的形式(true)还是使用当前打印空值的方式(false),默认是false。 用例: beeline --nullemptystring=false

Version: 0.13.0 (HIVE-4485)

 --incremental=[true/false]  从Hive 2.3版本往后默认是true,在它之前是默认为false。当设置为false时,为了最佳的展示列宽,完整的结果集会在展示之前被收集然后缓存起来。当设置为true时,结果集一旦被抓取到就会立即展示, 为了在展示列的填充额外消耗更少的延迟和内存。当你在客户端遭遇一个内存溢出时,推荐设置--incremental=true (因为抓取到的结果集非常大)。
 --incrementalBufferRows=NUMROWS

当打印行到标准输出时,保存在缓存中的行数,默认是1000。只有当 --incremental=true 和 --outputformat=table才适用。  用例: beeline --incrementalBufferRows=1000

Version: 2.3.0 (HIVE-14170)

 --maxHistoryRows=NUMROWS  存储Beeline 历史记录的最大行数。Version: 2.3.0 (HIVE-15166)
 --delimiter=;  设置Beeline的查询语句分隔符。允许用多个字符的分隔符,但是引号,斜杠和--是不允许的,默认是分号;    用例: beeline --delimiter=$$

Version: 3.0.0 (HIVE-10865)

 --convertBinaryArrayToString=[true/false]

展示二进制列数据为字符串或者位矩阵。用例: beeline --convertBinaryArrayToString=true

Version: 3.0.0 (HIVE-14786)

 --help  展示一个帮助信息。用例: beeline --help

2. beeline 使用示例

2.1 不配置用户名密码

beeline connect有几种方式,见hive-site.xml,缺省为NONE

<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
<description>
Expects one of [nosasl, none, ldap, kerberos, pam, custom].
Client authentication types.
NONE: no authentication check
LDAP: LDAP/AD based authentication
KERBEROS: Kerberos/GSSAPI authentication
CUSTOM: Custom authentication provider
(Use with property hive.server2.custom.authentication.class)
PAM: Pluggable authentication module
NOSASL: Raw transport
</description>
</property>

此时连接方式为

lenmom@Mi1701 ~$ beeline
Beeline version 1.2.1.spark2 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000/default
Connecting to jdbc:hive2://localhost:10000/default
Enter username for jdbc:hive2://localhost:10000/default:
Enter password for jdbc:hive2://localhost:10000/default:
。。。。
Connected to: Apache Hive (version 2.3.4)
Driver: Hive JDBC (version 1.2.1.spark2)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10014/default> show databases;
+----------------+--+
| database_name |
+----------------+--+
| default |
| orc |
+----------------+--+

2.2 用户名密码登录

hive-site.xml配置

<property>
<name>hive.server2.thrift.client.user</name>
<value>lenmom</value>
<description>Username to use against thrift client</description>
</property>
<property>
<name>hive.server2.thrift.client.password</name>
<value>123456</value>
<description>Password to use against thrift client</description>
</property>

使用密码连接

beeline> !connect jdbc:hive2://localhost:10000/default
Connecting to jdbc:hive2://localhost:10000/default
Enter username for jdbc:hive2://localhost:10000/default: lenmom
Enter password for jdbc:hive2://cdh-server2:10000/default: *****
Connected to: Apache Hive (version 2.3.4)
Driver: Hive JDBC (version 2.3.4)
Transaction isolation: TRANSACTION_REPEATABLE_READ

注意这里设置的用户要求对inode="/tmp/hive" 有执行权限,否则会出现下列问题:

Connecting to jdbc:hive2://localhost:10000/default
Enter username for jdbc:hive2://localhost:10000/default: lenmom
Enter password for jdbc:hive2://localhost:10000/default: **
Error: Failed to open new session: java.lang.RuntimeException: org.apache.hadoop.security.AccessControlException: Permission denied: user=lenmom, access=EXECUTE, inode="/tmp/hive":root:supergroup:drwxrwx---
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:319)
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkTraverse(FSPermissionChecker.java:259)
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:205)
at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:190)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPermission(FSDirectory.java:1698)
at org.apache.hadoop.hdfs.server.namenode.FSDirStatAndListingOp.getFileInfo(FSDirStatAndListingOp.java:108)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.getFileInfo(FSNamesystem.java:3817)
at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.getFileInfo(NameNodeRpcServer.java:1005)
at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.getFileInfo(ClientNamenodeProtocolServerSideTranslatorPB.java:843)

2.3 beeline连接hiveserver2使用用户名密码

beeline -u "jdbc:hive2://localhost:10000"  -n lenmom -p  123456
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512M; support was removed in 8.0
scan complete in 2ms
Connecting to jdbc:hive2://localhost:10000
Connected to: Apache Hive (version 2.3.4)
Driver: Hive JDBC (version 2.3.4)
Transaction isolation: TRANSACTION_REPEATABLE_READ
Beeline version 2.3.4 by Apache Hive
0: jdbc:hive2://localhost:10000>

2.4 类似hive-cli 的执行脚本功能

nohup beeline -u jdbc:hive2://127.0.0.1:10000  -n lenmom -p 123456  --color=true --silent=false  \
--hivevar p_date=${partitionDate} --hivevar f_date=${fileLocDate} \
-f hdfs_add_partition_dmp_clearlog.hql >> $logdir/load_${curDate}.log

3. beeline支持的操作

type command !help in beeline terminal

!help

output:

!addlocaldriverjar  Add driver jar file in the beeline client side.
!addlocaldrivername Add driver name that needs to be supported in the beeline
client side.
!all Execute the specified SQL against all the current connections
!autocommit Set autocommit mode on or off
!batch Start or execute a batch of statements
!brief Set verbose mode off
!call Execute a callable statement
!close Close the current connection to the database
!closeall Close all current open connections
!columns List all the columns for the specified table
!commit Commit the current transaction (if autocommit is off)
!connect Open a new connection to the database.
!dbinfo Give metadata information about the database
!describe Describe a table
!dropall Drop all tables in the current database
!exportedkeys List all the exported keys for the specified table
!go Select the current connection
!help Print a summary of command usage
!history Display the command history
!importedkeys List all the imported keys for the specified table
!indexes List all the indexes for the specified table
!isolation Set the transaction isolation for this connection
!list List the current connections
!manual Display the BeeLine manual
!metadata Obtain metadata information
!nativesql Show the native SQL for the specified statement
!nullemptystring Set to true to get historic behavior of printing null as
empty string. Default is false.
!outputformat Set the output format for displaying results
(table,vertical,csv2,dsv,tsv2,xmlattrs,xmlelements, and
deprecated formats(csv, tsv))
!primarykeys List all the primary keys for the specified table
!procedures List all the procedures
!properties Connect to the database specified in the properties file(s)
!quit Exits the program
!reconnect Reconnect to the database
!record Record all output to the specified file
!rehash Fetch table and column names for command completion
!rollback Roll back the current transaction (if autocommit is off)
!run Run a script from the specified file
!save Save the current variabes and aliases
!scan Scan for installed JDBC drivers
!script Start saving a script to a file
!set Set a beeline variable
!sh Execute a shell command
!sql Execute a SQL command
!tables List all the tables in the database
!typeinfo Display the type map for the current connection
!verbose Set verbose mode on

4. 常用的几个command

  • !connect url –连接不同的Hive2服务器
  • !exit –退出shell
  • !help –显示全部命令列表
  • !verbose –显示查询追加的明细

hive beeline详解的更多相关文章

  1. Hive安装配置指北(含Hive Metastore详解)

    个人主页: http://www.linbingdong.com 本文介绍Hive安装配置的整个过程,包括MySQL.Hive及Metastore的安装配置,并分析了Metastore三种配置方式的区 ...

  2. 使用java连接hive,并执行hive语句详解

    安装hadoop 和 hive我就不多说了,网上太多文章 自己看去 首先,在机器上打开hiveservice hive --service hiveserver -p 50000 & 打开50 ...

  3. Hive DQL详解

    1.select语法 SELECT [ALL | DISTINCT] select_expr, select_expr, ... FROM table_reference [WHERE where_c ...

  4. hive安装详解

    1.安装MYSQL simon@simon-Lenovo-G400:~$ sudo apt-get install mysql-server simon@simon-Lenovo-G400:~$ su ...

  5. HIVE 配置文件详解

    hive的配置: hive.ddl.output.format:hive的ddl语句的输出格式,默认是text,纯文本,还有json格式,这个是0.90以后才出的新配置: hive.exec.scri ...

  6. Hive命令详解

    http://blog.itpub.net/22778222/viewspace-1119892/  官方文档翻译 http://blog.csdn.net/hguisu/article/detail ...

  7. 九个最容易出错的 Hive sql 详解及使用注意事项

    阅读本文小建议:本文适合细嚼慢咽,不要一目十行,不然会错过很多有价值的细节. 文章首发于公众号:五分钟学大数据 前言 在进行数仓搭建和数据分析时最常用的就是 sql,其语法简洁明了,易于理解,目前大数 ...

  8. Hive 配置项详解

    hive.ddl.output.format: hive的ddl语句的输出格式, 默认是text,纯文本,还有json格式,这个是0.90以后才出的新配置: hive.exec.script.wrap ...

  9. HUE配置文件hue.ini 的hive和beeswax模块详解(图文详解)(分HA集群和非HA集群)

    不多说,直接上干货! 我的集群机器情况是 bigdatamaster(192.168.80.10).bigdataslave1(192.168.80.11)和bigdataslave2(192.168 ...

随机推荐

  1. 2021 小白版,360 行行行转 IT

    hey guys ,我是 cxuan,这一篇文章我就要和你聊聊编程如何学习,这一篇文章涉及的内容简直太多了,我将从入门开始,一步一步到如何提高,然后到一些学习的相关问题,还有一些计算机相关的术语等,干 ...

  2. OO_Unit2_Summary

    经过三周的自己电梯瞎设计,下次坐电梯想我想的可能就不是如何优化调度算法,而是千万别把自己死锁在电梯里了(手动狗头) 一.设计策略 1. 需求分析: 作业一:单部多线程可稍带电梯,一部电梯,固定楼层,不 ...

  3. OO第一单元作业——魔幻求导

    简介 本单元作业分为三次 第一次作业:需要完成的任务为简单多项式导函数的求解. 第二次作业:需要完成的任务为包含简单幂函数和简单正余弦函数的导函数的求解. 第三次作业:需要完成的任务为包含简单幂函数和 ...

  4. python学习 -- operator.itemgetter(), list.sort/sorted 以及lambda函数

    Python 中有非常方便高效的排序函数,下面主要介绍如何sort/sorted对list,dict进行排序. 1. 用list.sort /sorted 对list of tuples中第二个值进行 ...

  5. Java第三章基础学习课后题练习

    小结:final 类型 变量名 = 数值 定义常量使用 变量的原则*** 一定要"先声明,后使用",变量使用前必须先声明.这点就没php好玩:两种键盘输入方式InputStream ...

  6. Go-15-flag.String 获取系统参数

    场景: 启动应用程序时,需要传入系统参数.例如:./start --b /notebook --p true --n 8 package main import ( "fmt" f ...

  7. JMeter 实战案例

    案例1:博客网站后端测试 案例2:JPetStore 应用 案例1:博客网站后端测试 测试目标 测试博客网站后端的常用 HTTP 接口的访问方法. 展示 HTTP 请求的各类使用方法. 展示提取 JS ...

  8. linux too many open files 问题总结

    问题描述: kubernetes 集群使用promtail收集日志,发现一段时间有些机器日志收集不到查看promtail日志出现以下报错: error="filetarget.fsnotif ...

  9. SpringCloud(三)Hystrix断路器

    Hystrix断路器 概述 分布式系统面临的问题 复杂分布式体系结构中的应用程序有数十个依赖关系,每个依赖关系在某些时候将不可避免地失败 服务雪崩 多个微服务之间调用的时候,假设微服务A调用微服务B和 ...

  10. 1.6.5- HTML之自定义列表

    定义列表常用于对术语或名词进行解释和描述,定义列表的列表项前没有任何项目符号,其基本语法如下: <dl> <dt>定义标题</dt> <dd>定义描述, ...