user1956609
user1956609

Reputation: 2202

How to run a program, and then a command to execute within that program all at once

In Hadoop there is a SQL CLI called 'beeline' that allows you to write SQL and it distributes your query on your cluster.

On my linux box attached the cluster, if I type 'beeline' a new beeline shell appears. From there I can connect via jdbc, and then type SQL commands like this:

[me@phe41 ~]$ beeline

Hive version 0.11.0-SNAPSHOT by Apache

beeline>>> !connect jdbc:hive2://localhost:10000 scott tiger org.apache.hive.jdbc.HiveDriver
!connect jdbc:hive2://localhost:10000 scott tiger org.apache.hive.jdbc.HiveDriver

Connecting to jdbc:hive2://localhost:10000
Connected to: Hive (version 0.10.0)
Driver: Hive (version 0.10.0-SNAPSHOT)
Transaction isolation: TRANSACTION_REPEATABLE_READ

0: jdbc:hive2://localhost:10000>>> show tables;
show tables;
+-------------------+
|     tab_name      |
+-------------------+
| primitives        |
| src               |
| src1              |
| src_json          |
| src_sequencefile  |
| src_thrift        |
| srcbucket         |
| srcbucket2        |
| srcpart           |
+-------------------+

From the command line, I launch beeline which is its own program, and then connect to Hive which is its own program. How can I run "beeline" ... "!connect, etc" ... and "show tables;" all in a single line from the initial shell?

Upvotes: 2

Views: 1297

Answers (1)

ergonaut
ergonaut

Reputation: 7057

Use a here document

beeline << EOF
!connect, etc
show tables
EOF

Upvotes: 1

Related Questions