Created 10-18-2017 12:24 PM
I've seen little documentation on Hive View Rest API here
https://cwiki.apache.org/confluence/display/AMBARI/View+API
It looks like this is mostly to pull information out of ambari Views. I'm interested in posting to Ambari Hive View so I can import a bunch of saved queries. Is this something supported by the API and if so, where can I find this documented?
Created 10-21-2017 11:04 AM
For Hive View 2.0 you can try something like following:
# curl -u admin:admin -i -H 'X-Requested-By: ambari' -H 'Content-Type: application/json' -X POST -d '{"savedQuery":{"dataBase":"default","title":"Worksheet1","queryFile":"","owner":null,"shortQuery":"select * from customer LIMIT 3;"}}' "http://localhost:8080/api/v1/views/HIVE/versions/2.0.0/instances/AUTO_HIVE20_INSTANCE/savedQueries"
.
The saved script will be automatically stored inside the HDFS location something like "/user/admin/hive/scripts" (assuming that admin user is running the hive query)
.
Similarly if the user "maria_dev" runs the API call then the Saved Query SQL dat will be stored in the HDFS directory "/user/maria_dev/hive/scripts" directory:
# curl -u maria_dev:maria_dev -i -H 'X-Requested-By: ambari' -H 'Content-Type: application/json' -X POST -d '{"savedQuery":{"dataBase":"default","title":"Worksheet1","queryFile":"","owner":null,"shortQuery":"select * from customer LIMIT 5;"}}' "http://localhost:8080/api/v1/views/HIVE/versions/2.0.0/instances/AUTO_HIVE20_INSTANCE/savedQueries"
.
Created 10-23-2017 04:25 PM
This totally worked! Thanks @Jay SenSharma.
Note: I use the previous saved query name from my json source file as the "title" in the new saved query. This allowed me to uniquely identify each query in the UI. If I ever revisit this code, I may also need to query Rest to see if a specific query already exists and replace it or increment the title name or something.
-Dan
Created 10-23-2017 04:53 PM
Good to know that it worked for you. As the original issue is resolved, hence it will be also great if you can mark this HCC thread as Answered by clicking on the "Accept" Button on the correct answer. That way other HCC users can quickly find the solution when they encounter the same issue.