1

How do I generate and load multiple s3 file path in scala so that I can use :

   sqlContext.read.json ("s3://..../*/*/*")

I know I can use wildcards to read multiple files but is there any way so that I can generate the path ? For example my fIle structure looks like this: BucketName/year/month/day/files

       s3://testBucket/2016/10/16/part00000

These files are all jsons. The issue is I need to load just spacific duration of files, for eg. Say 16 days then I need to loado files for start day ( oct 16) : oct 1 to 16.

With 28 day duration for same start day I would like to read from Sep 18

Can some tell me any ways to do this ?

Learner
  • 35
  • 1
  • 7
  • Possible duplicate of [How to read multiple text files into a single RDD?](http://stackoverflow.com/questions/24029873/how-to-read-multiple-text-files-into-a-single-rdd) – eliasah Oct 16 '16 at 13:23
  • The issue is to generate the file paths dynamically – Learner Oct 16 '16 at 17:05

2 Answers2

1

You can take a look at this answer, You can specify whole directories, use wildcards and even CSV of directories and wildcards. E.g.:

sc.textFile("/my/dir1,/my/paths/part-00[0-5]*,/another/dir,/a/specific/file")

Or you can use AWS API to get the list of files locations and read those files using spark .

You can look into this answer to AWS S3 file search.

Community
  • 1
  • 1
bob
  • 4,595
  • 2
  • 25
  • 35
  • My issue is to how do I get the list of my keys in from start day how do I get the paths dynamically. All the paths . Start day - 28 – Learner Oct 16 '16 at 17:04
  • All of getting from input is start day and end date. Is there any utility to generate the dates between them so that I can create a list by concatenation – Learner Oct 16 '16 at 17:07
  • I updated my question based on ur solution. Is that a right way to do this ? – Learner Oct 16 '16 at 18:45
  • Yoi have three starts at the end in the url . its will read all the files under 2016 folder – bob Oct 16 '16 at 23:33
0

You can generate comma separated path list: sqlContext.read.json (s3://testBucket/2016/10/16/,s3://testBucket/2016/10/15/,...);

Igor Berman
  • 1,522
  • 10
  • 16