`

HiveServer2 入门使用

    博客分类:
  • hive
阅读更多

Beeline – 一个新的命令行Shell

HiveServer2 supports a new command shell Beeline that works with HiveServer2. It's a JDBC client that is based on the SQLLine CLI (http://sqlline.sourceforge.net/). There’s detailed documentation of SQLLine which is applicable to Beeline as well.

The Beeline shell works in both embedded mode as well as remote mode. In the embedded mode, it runs an embedded Hive (similar to Hive CLI) whereas remote mode is for connecting to a separate HiveServer2 process over Thrift. Starting inHive 0.14, when Beeline is used with HiveServer2, it also prints the log messages from HiveServer2 for queries it executes to STDERR.

 

Icon

In remote mode HiveServer2 only accepts valid Thrift calls – even in HTTP mode, the message body contains Thrift payloads.

 

 

Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式

启动HiverServer2 , ./bin/hiveserver2 

启动Beeline 

wangyue@wangyue-um:~/opt/hive/hive-0.12.0-cdh5.1.0$ ./bin/beeline 

beeline> !connect jdbc:hive2://localhost:10000

默认 用户名就是登录账号 密码为空

 

Beeline with NoSASL connection

If you'd like to connect via NOSASL mode, you must specify the authentication mode explicitly:

% bin/beeline
beeline> !connect jdbc:hive2://<host>:<port>/<db>;auth=noSasl hiveuser pass org.apache.hive.jdbc.HiveDriver

 

Beeline Commands

Command

Description

!<SQLLine command>

List of SQLLine commands available at http://sqlline.sourceforge.net/.

Example: !quit exits the Beeline client.

 

 

 

Beeline Command Options

 

The Beeline CLI supports these command line options:

Option

Description

-u <database URL>

The JDBC URL to connect to.

Usage: beeline -u db_URL 

-n <username>

The username to connect as.

Usage: beeline -n valid_user

-p <password>

The password to connect as.

Usage: beeline -p valid_password

-d <driver class>

The driver class to use.

Usage: beeline -d driver_class

-e <query>

Query that should be executed. Double or single quotes enclose the query string. This option can be specified multiple times.

Usage: beeline -e "query_string"

Support to run multiple sql statements separated by semicolons in a single query_string: 1.2.0 (HIVE-9877)
Bug to be fixed (running -e in background): workaround available (HIVE-6758)Bug fix (null pointer exception): 0.13.0 (
HIVE-5765)

Bug fix (--headerInterval not honored): 0.14.0 (HIVE-7647)

-f <file>

Script file that should be executed.

Usage: beeline -f filepath

Version: 0.12.0 (HIVE-4268)
Note: If the script contains tabs, query compilation fails in version 0.12.0. This bug is fixed in version 0.13.0 (HIVE-6359).

Bug to be fixed (running -f in background): workaround available (HIVE-6758)

--hiveconf property=value

Use value for the given configuration property. Properties that are listed in hive.conf.restricted.list cannot be reset with hiveconf (see Restricted List and Whitelist).

Usage: beeline --hiveconf prop1=value1

Version: 0.13.0 (HIVE-6173)

--hivevar name=value

Hive variable name and value. This is a Hive-specific setting in which variables can be set 
at the session level and referenced in Hive commands or queries.

Usage: beeline --hivevar var1=value1

--color=[true/false]

Control whether color is used for display. Default is false.

Usage: beeline --color=true

(Not supported for Separated-Value Output formats. See HIVE-9770)

--showHeader=[true/false]

Show column names in query results (true) or not (false). Default is true.

Usage: beeline --showHeader=false

--headerInterval=ROWS

The interval for redisplaying column headers, in number of rows, when outputformat is table. 
Default is 100.

Usage: beeline --headerInterval=50

(Not supported for Separated-Value Output formats. See HIVE-9770)

--fastConnect=[true/false]

When connecting, skip building a list of all tables and columns for tab-completion of 
HiveQL statements (true) or build the list (false). Default is true.

Usage: beeline --fastConnect=false

--autoCommit=[true/false]

Enable/disable automatic transaction commit. Default is false.

Usage: beeline --autoCommit=true

--verbose=[true/false]

Show verbose error messages and debug information (true) or do not show (false). 
Default is false.

Usage: beeline --verbose=true

--showWarnings=[true/false]

Display warnings that are reported on the connection after issuing any HiveQL commands. 
Default is false.

Usage: beeline --showWarnings=true

--showNestedErrs=[true/false]

Display nested errors. Default is false.

Usage: beeline --showNestedErrs=true

--numberFormat=[pattern]

Format numbers using a DecimalFormat pattern.

Usage: beeline --numberFormat="#,###,##0.00"

--force=[true/false]

Continue running script even after errors (true) or do not continue (false). Default is false.

Usage: beeline--force=true

--maxWidth=MAXWIDTH

The maximum width to display before truncating data, in characters, when outputformat is table. 
Default is to query the terminal for current width, then fall back to 80.

Usage: beeline --maxWidth=150

--maxColumnWidth=MAXCOLWIDTH

The maximum column width, in characters, when outputformat is table. Default is 15.

Usage: beeline --maxColumnWidth=25

--silent=[true/false]

Reduce the amount of informational messages displayed (true) or not (false). It also stops displaying the log messages for the query from HiveServer2 (Hive 0.14 and later) and the HiveQL commands (Hive 1.2.0 and later). Default is false.

Usage: beeline --silent=true

--autosave=[true/false]

Automatically save preferences (true) or do not autosave (false). Default is false.

Usage: beeline --autosave=true

--outputformat=[table/vertical/csv/tsv/dsv/csv2/tsv2]

Format mode for result display. Default is table. See Separated-Value Output Formats below for description of recommended sv options.

Usage: beeline --outputformat=tsv

Version: dsv/csv2/tsv2 added in 0.14.0 (HIVE-8615)

--truncateTable=[true/false]

If true, truncates table column in the console when it exceeds console length.

Version: 0.14.0 (HIVE-6928)

--delimiterForDSV= DELIMITER

The delimiter for delimiter-separated values output format. Default is '|' character.

Version: 0.14.0 (HIVE-7390)

--isolation=LEVEL

Set the transaction isolation level to TRANSACTION_READ_COMMITTED 
or TRANSACTION_SERIALIZABLE. 
See the "Field Detail" section in the Java Connection documentation.

Usage: beeline --isolation=TRANSACTION_SERIALIZABLE

--nullemptystring=[true/false]

Use historic behavior of printing null as empty string (true) or use current behavior of printing 
null as NULL (false). Default is false.

Usage: beeline --nullemptystring=false

Version: 0.13.0 (HIVE-4485)

--incremental=[true/false]

Print output incrementally.

--help

Display a usage message.

Usage: beeline --help

 

 

 

Server Connection

Hive CLI connects to a remote HiveServer1 instance using the Thrift protocol. To connect to a server, you specify the host name and optionally the port number of the remote server:

 

 

 

In contrast, Beeline connects to a remote HiveServer2 instance using JDBC. Thus, the connection parameter is a JDBC URL that’s common in JDBC-based clients:

 

 

 

Query Execution

Executing queries in Beeline is very similar to that in Hive CLI. In Hive CLI:

 

 

 

In Beeline:

 

 

 

 

Another important command is !quit (or !q), which allows you to exit interactive mode:

 

 

 

https://cwiki.apache.org/confluence/display/Hive/HiveServer2+Clients

http://blog.cloudera.com/blog/2014/02/migrating-from-hive-cli-to-beeline-a-primer/

尊重原创,未经允许不得转载:http://blog.csdn.net/stark_summer/article/details/45844403

0
0
分享到:
评论

相关推荐

    hive systemctl启停hiveserver2和metastore服务.pdf

    2. 使用`sudo systemctl enable hive-hiveserver2.service`和`sudo systemctl enable hive-metastore.service`设置服务在系统启动时自动启动。 3. 使用`sudo systemctl start hive-hiveserver2.service`和`sudo ...

    HiveServer2-JDBC及用户权限测试

    HiveServer2 通过使用 Kerberos 认证,可以确保用户身份的合法性,并且提供了基于角色的访问控制(RBAC)。 在进行 HiveServer2 测试时,需要配置 Kerberos 认证。首先,需要安装和配置 Kerberos 服务器,然后在 ...

    HiveServer2自定义身份验证

    ============Hive的beeline权限配置============ 1)HDFS修改core-site.xml配置 搜索 core-site.xml ...2)YARN (MR2 Included)修改core-site.xml配置 java.sql.SQLException: Could not open client transpor

    Hiveserver2 Beeline连接设置用户名和密码.docx

    用户现在可以通过 Beeline 使用用户名和密码连接到 HiveServer2。 总结,设置 Hiveserver2 Beeline 连接的用户名和密码涉及到自定义认证类的编写、Hive 和 Hadoop 配置文件的修改以及服务的重启。通过这样的方式,...

    hiveserver2 jdbc

    在描述中提到的"Hive1.2.1使用jdbc连接hive server2的所有jar包",意味着这个压缩包包含了所有必要的库文件,以确保在Hive 1.2.1版本下,能够成功建立并执行JDBC连接到HiveServer2。 要使用这些jar包,首先需要确保...

    hiveServer2logparser:HS2 日志的 Perl 解析器

    HiveServer2日志摘要器用法 #download latest scriptwget https://raw.githubusercontent.com/abajwa-hw/hiveServer2logparser/master/hiveServer2logparser.pl#run scriptperl hiveServer2logparser.pl &lt;path&gt;输出...

    docker-hiveserver2

    docker-hiveserver2

    HiveServer2 账号密码鉴权类编译 Jar 包

    HiveServer2 账号密码鉴权类编译 Jar 包

    cdh6.3.2升级hive至3.x后登陆HiveServer2连接失败.doc

    ### CDH 6.3.2 升级 Hive 至 3.x 后登录 HiveServer2 连接失败问题分析及解决方法 #### 一、问题背景与现象 在将 Cloudera Data Hub (CDH) 6.3.2 版本中的 Hive 升级到 3.x 版本后,用户在尝试通过 JDBC 连接到 ...

    php-thrift2-hiveserver2

    php连接hive, 基于thrift2 & hiveserver2 Thrift/transport/TSaslClientTransport.php 这里的username password也得改.... 密码为空的话随便填一个 这个文件务必也要一起修改, 否则涉及mapreduce的计算都无法执行

    Hive2.x系列驱动,

    标题 "Hive2.x系列驱动" 指的是Hive版本2.x的客户端连接器,这些驱动程序使得应用程序能够与Hive服务器进行交互,执行SQL查询并获取数据。Hive是一个基于Hadoop的数据仓库工具,它允许用户使用SQL语言处理存储在HDFS...

    pyhs2-0.6.0.tar.gz

    PyHS2的使用并不复杂,开发者可以通过创建一个`Client`实例连接到Hiveserver2,然后调用相关方法执行HQL语句或者获取结果集。例如: ```python from pyhs2 import connect from pyhs2.connect import ConnectParams...

    hive2-jdbc:Hive JDBC连接示例,包括简单和kerberos身份验证方法

    Hive JDBC连接示例该项目展示了如何使用各种不同的方法连接到Hiveserver2。 所有类仅适用于Hiveserver2。 正在使用Cloudera JDBC驱动程序,可以从下载。 在撰写本文时,最新版本为v2.5.15 。要求: 您需要下载驱动...

    一种基于数据仓库工具Hive组件的测试方法及系统.pdf

    1. 对集群 HiveServer2 当前状态进行检查,获取节点 HiveServer2_1 和节点 HiveServer2_2 的主备状态。 2. 对节点 HiveServer2_1 和节点 HiveServer2_2 执行强制状态切换动作,并检查状态切换是否成功。 3. 对集群 ...

    UDTF函数不生效问题.doc

    例如,如果使用Beeline连接到HiveServer2,可以执行如下命令: ```sql !beeline beeline&gt; !connect &lt;hiveserver2_url&gt; beeline&gt; RELOAD FUNCTIONS; ``` 2. **重启HiveServer2服务**: - 在某些情况下,简单...

    Transwarp Data Hub V4.2使用手册1

    - **命令行交互**:通过HiveServer1和HiveServer2,用户可以直接在终端上执行HQL(Hive Query Language)命令进行数据操作。 - **应用程序中的JDBC交互**:允许开发人员在Java应用中集成Inceptor,通过JDBC驱动...

    hive-server2.jar

    hive自定义安全认证使用

    CDH550@hive 使用及操作说明

    使用Beeline可以通过以下命令连接到HiveServer2: ```bash beeline -u jdbc:hive2://localhost:10000/default ``` 其中`localhost`应替换为实际的HiveServer2主机名或IP地址,端口号默认为10000,除非有特殊设置。 ...

    hive高可用1

    在生产环境中,推荐使用**Hiveserver2**,因为它具备以下优势: 1. **无需在应用端部署Hadoop和Hive客户端**,只需通过JDBC或Thrift接口即可与Hiveserver2通信。 2. **不直接暴露HDFS和Metastore给用户**,提高了...

    HIVE HA高可用性及详细使用

    - **服务端**:使用命令`nohup hive --service hiveserver2 &`来启动HiveServer2服务。 - **关闭服务**:先通过`ps -aux | grep hiveserver2`找到服务进程ID,然后使用`kill -9 &lt;PID&gt;`来终止服务。 - **监听服务端**...

Global site tag (gtag.js) - Google Analytics