Showing posts with label beeline. Show all posts
Showing posts with label beeline. Show all posts

Monday, 26 December 2022

hive: Beeline: Execute a query in non-interactive mode

Syntax

beeline -u jdbc:hive2:// -e 'query_to_execute'

 

Example

beeline -u jdbc:hive2:// -e 'SELECT * FROM emp'

 

[cloudera@quickstart hive]$ beeline -u jdbc:hive2:// -e 'SELECT * FROM emp'
scan complete in 3ms
Connecting to jdbc:hive2://
Connected to: Apache Hive (version 1.1.0-cdh5.13.0)
Driver: Hive JDBC (version 1.1.0-cdh5.13.0)
Transaction isolation: TRANSACTION_REPEATABLE_READ
OK
+---------+-----------+---------------------------------+---------------------------------+-------------------------------+-------------+-------------+--+
| emp.id  | emp.name  |           emp.hobbies           |    emp.technology_experience    |        emp.gender_age         | emp.rating  | emp.salary  |
+---------+-----------+---------------------------------+---------------------------------+-------------------------------+-------------+-------------+--+
| 1       | Hari      | ["Football","Cricket"]          | {"Java":"3.4Yrs","C":"4.5Yrs"}  | {"gender":"Male","age":30}    | -1.5        | 1000000.0   |
| 2       | Chamu     | ["Trekking","Watching movies"]  | {"Selenium":"5.6Yrs"}           | {"gender":"Female","age":38}  | 3.0         | 2500000.0   |
| 3       | Sailu     | ["Chess","Listening to music"]  | {"EmbeddedC":"9Yrs"}            | {"gender":"Female","age":32}  | 2.5         | 1300000.0   |
| 4       | Gopi      | ["Cricket"]                     | {"Datastage":"11Yrs"}           | {"gender":"Male","age":32}    | -0.7        | 8.1E7       |
| 5       | Rahim     | []                              | {}                              | {"gender":"Male","age":null}  | -0.7        | 500000.0    |
+---------+-----------+---------------------------------+---------------------------------+-------------------------------+-------------+-------------+--+
5 rows selected (0.982 seconds)
Beeline version 1.1.0-cdh5.13.0 by Apache Hive
Closing: 0: jdbc:hive2://
[cloudera@quickstart hive]$

 

 

 

 

 

 

Previous                                                    Next                                                    Home

HIVE: beeline: sql client to connect to HIVE

Step 1: Start hive server on port 12345.

$hive --service hiveserver2 --hiveconf hive.server2.thrift.port=12345
2021-01-14 21:43:19: Starting HiveServer2
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/Cellar/hive/3.1.2_2/libexec/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/hadoop/3.3.0/libexec/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Hive Session ID = 1a517e6e-e9fb-48ec-aaca-a746a1aaf626

 

Step 2: Execute following beeline command line tool to connect to hive server.

beeline jdbc:hive2://localhost:12345

$beeline jdbc:hive2://localhost:12345
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/Cellar/hive/3.1.2_2/libexec/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/hadoop/3.3.0/libexec/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
Beeline version 3.1.2 by Apache Hive
beeline> 

 

Execute the command ‘show tables’. to list all the tables.



 

 

 

Previous                                                    Next                                                    Home