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-18-2017 12:45 PM
Something like following you may try to see if this fulfills your requirement:
Get the list of "Saved Queries"
# curl -u admin:admin -i -H 'X-Requested-By: ambari' -X GET http://localhost:8080/api/v1/views/HIVE/versions/1.5.0/instances/AUTO_HIVE_INSTANCE/savedQueries
Posting the Saved Queries Involves two steps
Step-1). Place your hive queries into the HDFS using API call as following:
# curl -u admin:admin -i -H 'X-Requested-By: ambari' -H 'Content-Type: application/json' -X PUT -d '{"file":{"fileContent":"SELECT * FROM store LIMIT 300;","hasNext":false,"page":0,"pageCount":1}}' http://localhost:8080/api/v1/views/HIVE/versions/1.5.0/instances/AUTO_HIVE_INSTANCE/resources/file/%...
Step-2). Now use the same HDFS path from the step1 to save the query as following for Posting "Saved Queries"
# curl -u admin:admin -i -H 'X-Requested-By: ambari' -H 'Content-Type: application/json' -X POST -d '{"savedQuery":{"dataBase":"foodmart","title":"store sample query1","queryFile":"/user/admin/hive/jobs/hive-job-103-2017-10-18_12-09/query.hql","owner":"admin","shortQuery":null}}' http://localhost:8080/api/v1/views/HIVE/versions/1.5.0/instances/AUTO_HIVE_INSTANCE/savedQueries
.
Created 10-18-2017 12:50 PM
Additionally if you are planning to Migrate from Hive View 1.0 / 1.5 to Hive View 2.0 then you might want to take a look at the following API call:
https://docs.hortonworks.com/HDPDocuments/Ambari-2.5.2.0/bk_ambari-views/content/hive_upgrade_your_v...
Created 10-19-2017 12:20 PM
@Jay SenSharma I'm having trouble with this still. I tried what I actually wanted to post and, as below, tried with your sample. In both cases, I got a 500 server error. What am I doing wrong here?
curl -u admin:admin -i -H 'X-Requested-By: ambari' -H 'Content-Type: application/json' -X PUT -d '{"file":{"fileContent":"SELECT * FROM store LIMIT 300;","hasNext":false,"page":0,"pageCount":1}}' http://hdp-node00:8080/api/v1/views/HIVE/versions/2.0.0/instances/AUTO_HIVE20_INSTANCE/resources/fil...
HTTP/1.1 500 Server Error X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Pragma: no-cache Set-Cookie: AMBARISESSIONID=1woe7sttjidcw1rpi053bemdq5;Path=/;HttpOnly User: admin Content-Type: text/plain;charset=ISO-8859-1 Content-Length: 48 { "status": 500, "message": "Server Error" }
Created 10-18-2017 12:56 PM
@Jay SenSharma, this is great stuff. Thank you for your super-fast response.
Presumably this works the same for Hive 2, just change the path from /api/v1/views/HIVE/versions/1.5.0/instances/AUTO_HIVE_INSTANCE/ to /api/v1/views/HIVE/versions/2.0.0/instances/AUTO_HIVE20_INSTANCE/
-Dan
Created 10-18-2017 01:00 PM
Oh, and what I'm actually doing is migrating saved queries from Cloudera/Hue to Amabri Hive View. I found I can easily export queries to a list of JSON in Hue, but I don't see any native way of importing those to Ambari, so I'm going to try to load them via the Rest API using Python.
Created 10-18-2017 01:03 PM
Yes Based on your Hive View version you will need to make the following changes:
1.5.0 => Need to be replaced with your view version (like 2.0.0)
AUTO_HIVE_INSTANCE => This is the View Instance Name, Which might be different in your case. For example if you are using default Hive View 2.0 instance then the default view name should be "AUTO_HIVE20_INSTANCE" (if you have multiple View 2.0 instances then you will need to replace this with your own Hive View 2.0 instance name)
Created 10-18-2017 01:05 PM
If you are planning to migrate from Hue to Views then you should refer to this article as well: https://community.hortonworks.com/articles/54146/migrating-hue-to-ambari-views-24.html
.
More details on "Hue to View Migration" can be found here: https://docs.hortonworks.com/HDPDocuments/Ambari-2.5.2.0/bk_ambari-views/content/configuring_your_cl...
Created 10-18-2017 01:13 PM
Ah, yes, I also looked at this as well and found I'd actually have to migrate the Hue database first as it currently uses the embedded Sqlite3 database, which doesn't support remote access. This was encouraging though and is likely very helpful for those who configured thier Hue for an external database in the first place.
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"
.