HiveServer2 supports a command shell Beeline that works with HiveServer2. It’s a JDBC client that is based on the SQLLine CLI. 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 Command line) whereas remote mode is for connecting to a separate HiveServer2 process over Thrift. In this article, we will check commonly used HiveServer2 Beeline command line shell options with an examples.
You can run all Hive command line and Interactive options from Beeline CLI.
Read:
- Run HiveQL Script File Passing Parameter using Beeline CLI and Examples
- Steps to Connect to Hive Using Beeline CLI
- Commonly used Apache Hive Interactive Shell Command Options and Examples
- Commonly used Apache Hive Command Line Options and Examples
Beeline Command Line Shell Options
Below are the commonly used Beeline command line shell options:
Beeline Command Line Shell Options | Description |
-u <database url> | JDBC URL to connect to Hive database |
-r | Reconnect to last saved JDBC URL connection |
-n <username> | Username |
-p <password> | Password |
-d <driver class> | Driver class to be used if any |
-i <init file> | Script file for initialization of variables |
-e <query> | Query to be executed |
-f <exec file> | Execute script file |
-w (or) –password-file <password file> | Password file. Should provide full path of the file. |
–hiveconf property=value | Set value for given property |
–hivevar name=value | Hive variable name and value. You can use this variable inside HiveQL queries. |
–color=[true/false] | Set whether color is used for display |
–showHeader=[true/false] | Display header in the query output |
–headerInterval=ROWS; | Interval between which headers are displayed |
–fastConnect=[true/false] | Skip building table/column list for tab-completion |
–autoCommit=[true/false] | Enable or disable automatic transaction commit |
–verbose=[true/false] | Execute query in verbose mode |
–showWarnings=[true/false] | Display connection warnings |
–showNestedErrs=[true/false] | Display nested errors |
–numberFormat=[pattern] | Format numbers using DecimalFormat pattern |
–force=[true/false] | Continue script even after errors |
–maxWidth=MAXWIDTH | Maximum width of the terminal |
–maxColumnWidth=MAXCOLWIDTH | Maximum width to use when displaying columns |
–silent=[true/false] | Execute in silent mode |
–autosave=[true/false] | Automatically save preferences |
–outputformat=[table/vertical/csv2/tsv2/dsv/csv/tsv] | Format mode for result display |
–incremental=[true/false] | Defaults to false. When set to false, the entire result set is fetched and buffered before being displayed, yielding optimal display column sizing. When set to true, result rows are displayed immediately as they are fetched, yielding lower latency and memory usage at the price of extra display column padding. Setting –incremental=true is recommended if you encounter an OutOfMemory on the client side (due to the fetched result set size being large). |
–truncateTable=[true/false] | Truncate table column when it exceeds column length |
–delimiterForDSV=DELIMITER | Set delimiter for output format |
–isolation=LEVEL | Set the transaction isolation level |
–nullemptystring=[true/false] | Insert NULL for empty strings |
–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 | Command help option |
–delimiter= | Set output delimiter for data extraction |
Beeline Command Line Shell Options Examples
Display current date using Beeline
$ beeline -u jdbc:hive2://192.168.0.51:10000/training_db -n username -p password -e "select current_date()" Connecting to jdbc:hive2://192.168.0.51:10000/training_db Connected to: Apache Hive (version 1.2.1000.2.5.0.0-1245) Driver: Hive JDBC (version 1.2.1000.2.5.0.0-1245) Transaction isolation: TRANSACTION_REPEATABLE_READ +-------------+--+ | _c0 | +-------------+--+ | 2017-11-15 | +-------------+--+ 1 row selected (0.138 seconds) Beeline version 1.2.1000.2.5.0.0-1245 by Apache Hive Closing: 0: jdbc:hive2://192.168.0.51:10000/training_db
Export Hive Result in CSV format using Beeline Commands
You can suppress messages by using –silent=true options
$ beeline -u jdbc:hive2:// 192.168.0.51:10000/training_db -n impadmin -p impetus --silent=true --outputformat=csv2 -e "select * from stud" stud.id,stud.name,stud.dept 1,ABC,101 2,BCD,102 3,CDE,103 4,DEF,104 5,EFG,105