Support Questions

Find answers, ask questions, and share your expertise

UNIX sudo with beeline is not working.

avatar
Explorer

sudo su - ${user} -c "beeline -u 'jdbc:hive2://server:port,connectionstring' -e 'insert statement'; "

 

above line works fine if I take out sudo, with sudo it doesnt work, any help or advice is much appreciated.

 

Thanks!

1 ACCEPTED SOLUTION

avatar
Master Mentor

@S_Waseem 

I tried to insert the following statement to my hive table customer using your approach and it worked with a slight modification in your command.

Insert into customer values (5000, "CustFive", "BRN");

 

So can you please check and compare it with your command?

Changes:
Using the sudo approach which you mentioned by supplying the username and password to beeline using -n and -p options as following. The values in quotation mark were changed from "CustFive" to \"CustFive\" as they are surrounded by the -c " statement"


Example Output:

[root@newhwx1 ~]# export user_hive=hive

[root@newhwx1 ~]# echo ${user_hive}
hive

[root@newhwx1 ~]# sudo su - ${user_hive} -c "beeline -n hive -p hive -u 'jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -e 'insert into customer values (5000, \"CustFive\", \"BRN\")'"


Connecting to jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ
INFO : Tez session hasn't been created yet. Opening session
INFO : Dag name: insert into customer values (5000, ..."BRN")(Stage-1)
INFO : Status: Running (Executing on YARN cluster with App id application_1579040432494_27933)

INFO : Loading data to table default.customer from hdfs://My-NN-HA/apps/hive/warehouse/customer/.hive-staging_hive_2020-02-05_22-12-33_107_183476754828623767-2/-ext-10000
--------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 0 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 6.46 s 
--------------------------------------------------------------------------------
INFO : Table default.customer stats: [numFiles=5, numRows=5, totalSize=90, rawDataSize=85]
No rows affected (22.328 seconds)
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
Closing: 0: jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2


Output of "select * from customer" later.

[root@newhwx1 ~]# sudo su - ${user_hive} -c "beeline -n hive -p hive -u 'jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -e 'select * from customer'"


Connecting to jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ
+------------------+--------------------+----------------+--+
| customer.custid | customer.custname | customer.city |
+------------------+--------------------+----------------+--+
| 1000 | CustOne | BLR |
| 2000 | CustTwo | PUNE |
| 3000 | CustThree | HYD |
| 4000 | CustFour | NSW |
| 5000 | CustFive | BRN |
+------------------+--------------------+----------------+--+
5 rows selected (1.108 seconds)
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
Closing: 0: jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

 

.

.

 

View solution in original post

2 REPLIES 2

avatar
Master Mentor

@S_Waseem 

I tried to insert the following statement to my hive table customer using your approach and it worked with a slight modification in your command.

Insert into customer values (5000, "CustFive", "BRN");

 

So can you please check and compare it with your command?

Changes:
Using the sudo approach which you mentioned by supplying the username and password to beeline using -n and -p options as following. The values in quotation mark were changed from "CustFive" to \"CustFive\" as they are surrounded by the -c " statement"


Example Output:

[root@newhwx1 ~]# export user_hive=hive

[root@newhwx1 ~]# echo ${user_hive}
hive

[root@newhwx1 ~]# sudo su - ${user_hive} -c "beeline -n hive -p hive -u 'jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -e 'insert into customer values (5000, \"CustFive\", \"BRN\")'"


Connecting to jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ
INFO : Tez session hasn't been created yet. Opening session
INFO : Dag name: insert into customer values (5000, ..."BRN")(Stage-1)
INFO : Status: Running (Executing on YARN cluster with App id application_1579040432494_27933)

INFO : Loading data to table default.customer from hdfs://My-NN-HA/apps/hive/warehouse/customer/.hive-staging_hive_2020-02-05_22-12-33_107_183476754828623767-2/-ext-10000
--------------------------------------------------------------------------------
VERTICES STATUS TOTAL COMPLETED RUNNING PENDING FAILED KILLED
--------------------------------------------------------------------------------
Map 1 .......... SUCCEEDED 1 1 0 0 0 0
--------------------------------------------------------------------------------
VERTICES: 01/01 [==========================>>] 100% ELAPSED TIME: 6.46 s 
--------------------------------------------------------------------------------
INFO : Table default.customer stats: [numFiles=5, numRows=5, totalSize=90, rawDataSize=85]
No rows affected (22.328 seconds)
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
Closing: 0: jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2


Output of "select * from customer" later.

[root@newhwx1 ~]# sudo su - ${user_hive} -c "beeline -n hive -p hive -u 'jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -e 'select * from customer'"


Connecting to jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2
Connected to: Apache Hive (version 1.2.1000.2.6.5.0-292)
Driver: Hive JDBC (version 1.2.1000.2.6.5.0-292)
Transaction isolation: TRANSACTION_REPEATABLE_READ
+------------------+--------------------+----------------+--+
| customer.custid | customer.custname | customer.city |
+------------------+--------------------+----------------+--+
| 1000 | CustOne | BLR |
| 2000 | CustTwo | PUNE |
| 3000 | CustThree | HYD |
| 4000 | CustFour | NSW |
| 5000 | CustFive | BRN |
+------------------+--------------------+----------------+--+
5 rows selected (1.108 seconds)
Beeline version 1.2.1000.2.6.5.0-292 by Apache Hive
Closing: 0: jdbc:hive2://newhwx1.example.com:2181,newhwx2.example.com:2181,newhwx3.example.com:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2

 

.

.

 

avatar
Explorer

Hello Sir,

 

It worked... thank you so much!!!