Delete File

This operation is used to delete a file from the directory.

Following interfaces provide functionality to perform delete file operation:

DFS Client API

Following code is used to delete file from the directory. org.apache.Hadoop.fs.FileSystem.delete(org.apache.hadoop.fs.Path, boolean) is used to delete a file from the path provided. Second argument signifies whether delete operation will execute recursively or single time. Providing false will delete single file only.

import java.io.IOException;

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 DeleteObject {
	/*
	 * This program deletes the specified file from the 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://192.168.0.1:9000"); // URL for your namenode
		conf.set(DFSConfigKeys.DFS_REPLICATION_KEY, "3"); // Replication count for files you write
		
		//Initialize DFS FileSystem object with QueryIO configurations 
		FileSystem dfs = FileSystem.get(conf);
		dfs.delete(new Path("/queryio/demo/file1.txt"), false); // Deleting just the file
	}
}

	

WEBHDFS API

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

Syntax of curl command for delete operation:

curl -i -X DELETE "http://<host>:<port>/webhdfs/v1/<path>?user.name=<username>&op=DELETE"
Sample Request:
curl -i -X DELETE "http://192.168.0.1:50070/webhdfs/v1/queryio/demo/file1.txt?user.name=admin&op=DELETE"	
	

DELETE file operation using WEBHDFS api returns a JSON object.

The following is the actual HTTP request:

DELETE /webhdfs/v1/queryio/demo/file1.txt?user.name=admin&op=DELETE 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
Host: 192.168.0.1:50070
Accept: */*
	

Following is the HTTP response sent when QueryIO Server successfully deletes a file:

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

{"boolean":true}	
	


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.