Get list of Hadoop SQL Queries

GET Hadoop SQL List operation is used to fetch all the Hadoop SQL Queries from the database.

S3 Compatible REST API

Following code is used to fetch all the Hadoop SQL Queries.

java.net.HttpURLConnection is used to create a GET request "hadoopsql" appeded to the URL. Request property(hadoopsql-id) is not set so that all Hadoop SQL Queries can be fetched.

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import org.apache.http.HttpStatus;

public class QueryOperations {
	
		/*
	 	 * This program fetches list of Hadoop SQL Query
		 * @param serverURL: URL of s3 server.
		 * @param token: authorization token.
		 */
	public void getHadoopQueryList(String serverURL, String token)
			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.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) {
				e.printStackTrace();
			}
			if (httpCon != null) {
				httpCon.disconnect();	//close connection
			}
		}
	}
}
	


Copyright ©
  • Contact Us
  • Contact Us
  • 2018 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.