AnsweredAssumed Answered

How to pass connection credentials to the hive --service beeline shell from local script

Question asked by bustout on Feb 3, 2014
Latest reply on Feb 3, 2014 by bustout
We need to be able to run scripts as different users from the local commandline on a Linux box. I can connect from the hive shell and do the following:

    user1@somehost ~]$ hive --service beeline
    Beeline version 0.12-mapr-1311 by Apache Hive
    beeline>!connect jdbc:hive2://somenode:10000
    scan complete in 3ms
    Connecting to jdbc:hive2://somenode:10000
    Enter username for jdbc:hive2://somenode:10000: user1
    Enter password for jdbc:hive2://somenode:10000: <password>
    Connected to: Hive (version 0.12-mapr-1311)
    Driver: Hive (version 0.12-mapr-1311)
    Transaction isolation: TRANSACTION_REPEATABLE_READ
    0: jdbc:hive2://somenode:10000> CREATE TABLE web_log_lee_test_3a(viewTime INT, userid BIGINT, url STRING, referrer STRING, ip STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
    No rows affected (1.256 seconds)
    0: jdbc:hive2://somenode:10000> load data local inpath '/opt/HIVE-TMP/sample-table1.txt' into table web_log_lee_test_3a;
    No rows affected (0.45 seconds)
    0: jdbc:hive2://somenode:10000> select * from web_log_lee_test_3a;
    +-------------+---------+--------------------------+--------------------------+----------------+
    |  viewtime   | userid  |           url            |         referrer         |       ip       |
    +-------------+---------+--------------------------+--------------------------+----------------+
    | 1320352532  | 1001    | http://www.mapr.com/doc  | http://www.mapr.com      | 192.168.10.1   |
    | 1320352533  | 1002    | http://www.mapr.com      | http://www.example.com   | 192.168.10.10  |
    | 1320352546  | 1001    | http://www.mapr.com      | http://www.mapr.com/doc  | 192.168.10.1   |
    +-------------+---------+--------------------------+--------------------------+----------------+
    3 rows selected (0.283 seconds)
    0: jdbc:hive2://somenode:10000>

I want to be able to do this from like a shell script. Any examples would be greatly appreciated.

Outcomes