Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
Read files along with subdirectories from s3 using sc.textFile

Trying to read the s3 data from java spark context:

"mapreduce.input.fileinputformat.input.dir.recursive", "true"
jsc.textFile(filePath);

It was working for me when I have only files insides hour folders:

s3://<year>/<month>/<day>/<hour>/<files>
jsc.textFile("s3://<year>/<month>/<day>");

Now, in S3 parallel to hour folder we may have new_folder as well

s3://<year>/<month>/<day>/<hour>/<files>
s3://<year>/<month>/<day>/<hour>/<new_folder>/<files>

Below code ignoring the files under new_folder

jsc.textFile("s3://<year>/<month>/<day>");

Tried with multiple regular expression, but my method "isPathExist" always return false

jsc.textFile("s3n://<year>/<month>/<day>/*/<regular_expression>");

Checked S3 path using below method, which returns false

private static boolean isPathExists(String folderPath, String bucket, String accessKey, String secret) {
    AWSCredentials cred = new BasicAWSCredentials(accessKey, secret);
    AmazonS3 s3 = new AmazonS3Client(cred);
    ObjectListing objectListing = s3
            .listObjects(new ListObjectsRequest().withBucketName(bucket).withPrefix(folderPath));
    return !objectListing.getObjectSummaries().isEmpty();
}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you want all subdirectories, then use two stars.

jsc.textFile("s3://<year>/<month>/<day>/**");

And files in those directories, one more star (I think)

jsc.textFile("s3://<year>/<month>/<day>/**/*");
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!