Delete Hadoop SQL Query

DELETE Hadoop SQL operation is used to delete a Hadoop SQL Query from the database.

S3 Compatible REST API

Following code is used to delete a Hadoop SQL Query.

java.net.HttpURLConnection is used to create a DELETE request "hadoopsql" appended to the URL. Request property(hadoopsql-id) is set to id of the Hadoop SQL Query to be deleted.

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 deletes a given Hadoop SQL Query 
		 * @param serverURL: URL of s3 server.
		 * @param token: authorization token.
		 * @param queryId: Id of the query to be deleted
		 */
	public void deleteHadoopSQL(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("DELETE");		//DELETE request is used

			httpCon.setRequestProperty("authorization", token);	//provides authorization token for authentication
			
			httpCon.setRequestProperty("hadoopsql-id", queryId);	//provides id of the query to be deleted
				
			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.