Delete directory

DELETE directory operation can be implemented using following interfaces.

DFS Client API

FileSystem.delete(org.apache.hadoop.fs.Path) is used to delete a directory from the QueryIO cluster. NameNode URL and replication count are provided in the Hadoop configuration and it is used to create file system object.


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.DFSConfigKeys;

public class DeleteBucket {
	 * This program deletes the specified directory from HDFS.
	public static void main(String[] args) throws IOException{
		Configuration conf = new Configuration(true);	//Create a configuration object to define hdfs properties
		conf.set(DFSConfigKeys.FS_DEFAULT_NAME_KEY, "hdfs://"); // URL for your namenode
		conf.set(DFSConfigKeys.DFS_REPLICATION_KEY, "3"); // Replication count for files you write
		FileSystem dfs = FileSystem.get(conf);	//Initialize DFS FileSystem object with QueryIO configurations 
		dfs.delete(new Path("/queryio/demo/"), true); // Deletes files in the folder recursively


HTTP DELETE operation can be used for delete directory operation. Following sample is explained using curl command.

Syntax of curl command used is

curl -i -X DELETE "http://<host>:<port>/<path>?<username>&op=DELETE[&recursive=<true|false>]"
Sample Request:
curl -i -X DELETE ""

Above request will delete directory "demo" and all its subdirectories.

The following is the actual HTTP request:

DELETE /webhdfs/v1/queryio/demo? HTTP/1.1	
User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
Accept: */*

Delete directory operation using WEBHDFS api returns a JSON object. If successful, the HTTP 200 response code is returned. Following is the HTTP response sent when QueryIO Server successfully deletes a directory:

HTTP/1.1 200 OK
Content-Type: application/json
Expires: Thu, 01-Jan-1970 00:00:00 GMT
Set-Cookie: hadoop.auth="u=admin&p=admin&t=simple&e=1356635081222&s=GrDdraO+6ZAYdridUnl3YsSqQGE=";Path=/
Transfer-Encoding: chunked
Server: Jetty(6.1.26)


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.