Skip to content

Instantly share code, notes, and snippets.

@Blackmist
Created June 5, 2017 13:42
Show Gist options
  • Save Blackmist/10fc586f0467af2c39519ede3dccba6c to your computer and use it in GitHub Desktop.
Save Blackmist/10fc586f0467af2c39519ede3dccba6c to your computer and use it in GitHub Desktop.
Create and insert data into a Hive table using REST
# This example assumes you are using an HDInsight cluster.
# It was tested with HDInsight 3.5, but probably works on anything around/after that.
# the name of the HDInsight login account. Usually admin
LOGINNAME='admin'
PASSWORD='password for the login account'
# Just the name, not the FQDN
CLUSTERNAME='the name of your HDInsight cluster'
# Create a new table named 'testtable'
curl -u $LOGINNAME:$PASSWORD -X PUT -HContent-type:application/json -d '{"columns": [ {"name":
"id","type":"bigint"},{"name":"price","type":"float"}]}' "https://$CLUSTERNAME.azurehdinsight.net/templeton/v1/ddl/datab
ase/default/table/testtable?user.name=$LOGINNAME"
# The return value is:
# {"database":"default","table":"testtable"}
# Insert data into the table
curl -u $LOGINNAME:$PASSWORD -d user.name=$LOGINNAME -d execute="insert into table testtable values
('1',1.99), ('2',0.99), ('3',4.99);" "https://$CLUSTERNAME.azurehdinsight.net/templeton/v1/hive"
# The return value is similar to the following:
# {"id":"job_1496324379582_0008"}
# The job ID is the process that performs this query.
# To check the status of the job, use the following:
JOBID='the job ID from the previous response'
curl -u $LOGINNAME:$PASSWORD -G -d user.name=$LOGINNAME "https://$CLUSTERNAME.azurehdinsight.net/templeton/v1/jobs/$JOBID"
# This returns a JSON document. Look for at the value of .status.state. It indicates the status of the job.
# If you have the JQ utility, you can easily view this element by using the following:
# curl -u $LOGINNAME:$PASSWORD -G -d user.name=$LOGINNAME "https://$CLUSTERNAME.azurehdinsight.net/templeton/v1/jobs/$JOBID" | jq .status.state
# Once the status changes to 'SUCCEEDED', the data has been inserted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment