Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
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!
Created 02-05-2020 02:20 PM
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
.
.
Created 02-05-2020 02:20 PM
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
.
.
Created 02-06-2020 11:25 AM
Hello Sir,
It worked... thank you so much!!!