0

Is there a way to run hadoop commands in the mapper?

For example I want to run

hdfs dfs -text /path/to/file 

and I will use that output for my mapper logic. Or is there an alternative?

Such as running the command hdfs dfs -text /path/to/file as a subprocess with Java

1 Answer 1

1

Better is to use the Java HDFS API to open an HDFS file and read the contents into a variable that you can use.

For example:

InputStream is = FileSystem.get(yourConfigurationObject).open(new Path("/path/to/file"));
Sign up to request clarification or add additional context in comments.

2 Comments

How could I perform an -ls? I want to store all the paths to a file. There is so much documentation. I am not sure where to look and how to look for it.
fs.listStatus(new Path("/your/path")) will return an array of FileStatus, from which each has a getPath() method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.