GET a given Hadoop SQL Query

GET Hadoop SQL operation is used to fetch given Hadoop SQL Query from the database.

S3 Compatible REST API

Following code is used to fetch a Hadoop SQL Query. is used to create a GET request "hadoopsql" appended to the URL. Request property(hadoopsql-id) is set to id of the Hadoop SQL Query to be retrieved.


import org.apache.http.HttpStatus;

public class QueryOperations {
	 	 * This program fetches a given Hadoop SQL Query
		 * @param serverURL: URL of s3 server.
		 * @param token: authorization token.
		 * @param queryId: Id of the query to be retrieved
	public void getHadoopSQL(String serverURL, String token, String queryId)
			throws Exception {
		URL url = null;
		HttpURLConnection httpCon = null;
		InputStream is = null;
		try {
			/* append "/" at end of serverURL */
			if (!serverURL.endsWith("/")) {
				serverURL = serverURL + "/";
			url = new URL(serverURL + "hadoopsql");	//append "hadoopsql" to the serverURL and create a new URL object

			//Returns a URLConnection object that represents a connection to the remote object referred to by the URL.
			httpCon = (HttpURLConnection) url.openConnection();

			httpCon.setDoOutput(true);	// to use the URL connection for output
			httpCon.setRequestMethod("GET");	//GET request is used

			httpCon.setRequestProperty("authorization", token);	//provides authorization token for authentication
			httpCon.setRequestProperty("hadoopsql-id", queryId);	//provides id of the query to be retrieved
			httpCon.connect();	//Opens a communications link to the resource reference by the URL

			if (httpCon.getResponseCode() == HttpStatus.SC_OK) {	//check for OK response
				is = httpCon.getInputStream();
				// Process response here
		} finally {
			try {
				if (is != null)
					is.close();	//close InputStream
			} catch (IOException e) {
			if (httpCon != null) {
				httpCon.disconnect();	//close connection

Copyright 2017 QueryIO Corporation. All Rights Reserved.

QueryIO, "Big Data Intelligence" and the QueryIO Logo are trademarks of QueryIO Corporation. Apache, Hadoop and HDFS are trademarks of The Apache Software Foundation.