{"action":"created","comment":{"url":"https://api.github.com/repos/chaordic/ignition-core/pulls/comments/39419403","id":39419403,"diff_hunk":"@@ -194,5 +199,102 @@ object SparkContextUtils {\n       else\n         objectHadoopFile(paths, minimumPaths)\n     }\n+\n+    def parallelTextFiles(paths: Seq[String], maxBytesPerPartition: Long): RDD[String] = {\n+      val s3Paths = parallelListFiles(paths)\n+      val buckets = buildBuckets(s3Paths, maxBytesPerPartition)\n+      val files = buckets.flatMap(_.paths)\n+\n+      val s3Key = sc.hadoopConfiguration.get(\"fs.s3n.awsAccessKeyId\")\n+      val s3Secret = sc.hadoopConfiguration.get(\"fs.s3n.awsSecretAccessKey\")\n+\n+      val partitionedFiles = sc.parallelize(files).map(file => file -> ()).partitionBy(createPartitioner(buckets))\n+\n+      partitionedFiles.mapPartitions { files =>\n+        val conf = new Configuration()\n+        conf.set(\"fs.s3n.awsAccessKeyId\", s3Key)\n+        conf.set(\"fs.s3n.awsSecretAccessKey\", s3Secret)\n+        val codecFactory = new CompressionCodecFactory(conf)\n+        files.map { case (path, _) => path } flatMap { s3Path =>\n+          val fileSystem = FileSystem.get(new java.net.URI(s3Path), conf)\n+          val path = new Path(s3Path)\n+          val inputStream = Option(codecFactory.getCodec(path)) match {\n+            case Some(compression) => compression.createInputStream(fileSystem.open(path))\n+            case None => fileSystem.open(path)\n+          }\n+          Source.fromInputStream(inputStream).getLines()\n+        }\n+      }\n+    }\n+\n+    private def createPartitioner(buckets: Seq[Bucket]): Partitioner = {","path":"src/main/scala/ignition/core/jobs/utils/SparkContextUtils.scala","position":64,"original_position":64,"commit_id":"056b4f82f6e91de5bdf3ebab53a8f82886e9bcac","original_commit_id":"056b4f82f6e91de5bdf3ebab53a8f82886e9bcac","user":{"login":"luisguilherme","id":70356,"avatar_url":"https://avatars.githubusercontent.com/u/70356?v=3","gravatar_id":"","url":"https://api.github.com/users/luisguilherme","html_url":"https://github.com/luisguilherme","followers_url":"https://api.github.com/users/luisguilherme/followers","following_url":"https://api.github.com/users/luisguilherme/following{/other_user}","gists_url":"https://api.github.com/users/luisguilherme/gists{/gist_id}","starred_url":"https://api.github.com/users/luisguilherme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luisguilherme/subscriptions","organizations_url":"https://api.github.com/users/luisguilherme/orgs","repos_url":"https://api.github.com/users/luisguilherme/repos","events_url":"https://api.github.com/users/luisguilherme/events{/privacy}","received_events_url":"https://api.github.com/users/luisguilherme/received_events","type":"User","site_admin":false},"body":"You can do everything here.\r\n\r\n```scala\r\nprivate def createPartitioner(paths: Seq[S3File]) = {\r\n  case class Accumulator(path: String, partition: Int, size: Long = 0) {\r\n    def toEntry = path -> partition\r\n  }\r\n  val mappings = paths.scanLeft(None)  {\r\n    case (None, file) => \r\n      Option(Accumulator(file.path, 0, file.size))\r\n    case (Some(Accumulator(_, partition, size), file) if size + file.size > maxBytesPerPartition =>\r\n      Option(Accumulator(file.path, partition+1, file.size)\r\n   case (Some(Accumulator(_, partition, size), file) =>\r\n      Option(Accumulator(file.path, partition, size + file.size)\r\n  }.flatten\r\n  val size = mappings.last.partition + 1\r\n  val partitions: Map[Any, Int] = mappings.map(_.toEntry).toMap\r\n  new Partitioner {\r\n    override def numPartitions: Int = size\r\n    override def getPartition(key: Any): Int = partitions(key)\r\n  }\r\n}\r\n```\r\n\r\nWDYT?","created_at":"2015-09-14T17:11:21Z","updated_at":"2015-09-14T17:11:21Z","html_url":"https://github.com/chaordic/ignition-core/pull/54#discussion_r39419403","pull_request_url":"https://api.github.com/repos/chaordic/ignition-core/pulls/54","_links":{"self":{"href":"https://api.github.com/repos/chaordic/ignition-core/pulls/comments/39419403"},"html":{"href":"https://github.com/chaordic/ignition-core/pull/54#discussion_r39419403"},"pull_request":{"href":"https://api.github.com/repos/chaordic/ignition-core/pulls/54"}}},"pull_request":{"url":"https://api.github.com/repos/chaordic/ignition-core/pulls/54","id":44805335,"html_url":"https://github.com/chaordic/ignition-core/pull/54","diff_url":"https://github.com/chaordic/ignition-core/pull/54.diff","patch_url":"https://github.com/chaordic/ignition-core/pull/54.patch","issue_url":"https://api.github.com/repos/chaordic/ignition-core/issues/54","number":54,"state":"open","locked":false,"title":"Parallel read and list files","user":{"login":"fparisotto","id":551145,"avatar_url":"https://avatars.githubusercontent.com/u/551145?v=3","gravatar_id":"","url":"https://api.github.com/users/fparisotto","html_url":"https://github.com/fparisotto","followers_url":"https://api.github.com/users/fparisotto/followers","following_url":"https://api.github.com/users/fparisotto/following{/other_user}","gists_url":"https://api.github.com/users/fparisotto/gists{/gist_id}","starred_url":"https://api.github.com/users/fparisotto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fparisotto/subscriptions","organizations_url":"https://api.github.com/users/fparisotto/orgs","repos_url":"https://api.github.com/users/fparisotto/repos","events_url":"https://api.github.com/users/fparisotto/events{/privacy}","received_events_url":"https://api.github.com/users/fparisotto/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-11T17:00:57Z","updated_at":"2015-09-14T17:11:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"146b029b5bd136b1f39235a8b02ca13ec80405d6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/chaordic/ignition-core/pulls/54/commits","review_comments_url":"https://api.github.com/repos/chaordic/ignition-core/pulls/54/comments","review_comment_url":"https://api.github.com/repos/chaordic/ignition-core/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chaordic/ignition-core/issues/54/comments","statuses_url":"https://api.github.com/repos/chaordic/ignition-core/statuses/056b4f82f6e91de5bdf3ebab53a8f82886e9bcac","head":{"label":"fparisotto:parallel-read-listfiles","ref":"parallel-read-listfiles","sha":"056b4f82f6e91de5bdf3ebab53a8f82886e9bcac","user":{"login":"fparisotto","id":551145,"avatar_url":"https://avatars.githubusercontent.com/u/551145?v=3","gravatar_id":"","url":"https://api.github.com/users/fparisotto","html_url":"https://github.com/fparisotto","followers_url":"https://api.github.com/users/fparisotto/followers","following_url":"https://api.github.com/users/fparisotto/following{/other_user}","gists_url":"https://api.github.com/users/fparisotto/gists{/gist_id}","starred_url":"https://api.github.com/users/fparisotto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fparisotto/subscriptions","organizations_url":"https://api.github.com/users/fparisotto/orgs","repos_url":"https://api.github.com/users/fparisotto/repos","events_url":"https://api.github.com/users/fparisotto/events{/privacy}","received_events_url":"https://api.github.com/users/fparisotto/received_events","type":"User","site_admin":false},"repo":{"id":30024631,"name":"ignition-core","full_name":"fparisotto/ignition-core","owner":{"login":"fparisotto","id":551145,"avatar_url":"https://avatars.githubusercontent.com/u/551145?v=3","gravatar_id":"","url":"https://api.github.com/users/fparisotto","html_url":"https://github.com/fparisotto","followers_url":"https://api.github.com/users/fparisotto/followers","following_url":"https://api.github.com/users/fparisotto/following{/other_user}","gists_url":"https://api.github.com/users/fparisotto/gists{/gist_id}","starred_url":"https://api.github.com/users/fparisotto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fparisotto/subscriptions","organizations_url":"https://api.github.com/users/fparisotto/orgs","repos_url":"https://api.github.com/users/fparisotto/repos","events_url":"https://api.github.com/users/fparisotto/events{/privacy}","received_events_url":"https://api.github.com/users/fparisotto/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fparisotto/ignition-core","description":"Ignition-core","fork":true,"url":"https://api.github.com/repos/fparisotto/ignition-core","forks_url":"https://api.github.com/repos/fparisotto/ignition-core/forks","keys_url":"https://api.github.com/repos/fparisotto/ignition-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fparisotto/ignition-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fparisotto/ignition-core/teams","hooks_url":"https://api.github.com/repos/fparisotto/ignition-core/hooks","issue_events_url":"https://api.github.com/repos/fparisotto/ignition-core/issues/events{/number}","events_url":"https://api.github.com/repos/fparisotto/ignition-core/events","assignees_url":"https://api.github.com/repos/fparisotto/ignition-core/assignees{/user}","branches_url":"https://api.github.com/repos/fparisotto/ignition-core/branches{/branch}","tags_url":"https://api.github.com/repos/fparisotto/ignition-core/tags","blobs_url":"https://api.github.com/repos/fparisotto/ignition-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fparisotto/ignition-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fparisotto/ignition-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/fparisotto/ignition-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fparisotto/ignition-core/statuses/{sha}","languages_url":"https://api.github.com/repos/fparisotto/ignition-core/languages","stargazers_url":"https://api.github.com/repos/fparisotto/ignition-core/stargazers","contributors_url":"https://api.github.com/repos/fparisotto/ignition-core/contributors","subscribers_url":"https://api.github.com/repos/fparisotto/ignition-core/subscribers","subscription_url":"https://api.github.com/repos/fparisotto/ignition-core/subscription","commits_url":"https://api.github.com/repos/fparisotto/ignition-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/fparisotto/ignition-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/fparisotto/ignition-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/fparisotto/ignition-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/fparisotto/ignition-core/contents/{+path}","compare_url":"https://api.github.com/repos/fparisotto/ignition-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fparisotto/ignition-core/merges","archive_url":"https://api.github.com/repos/fparisotto/ignition-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fparisotto/ignition-core/downloads","issues_url":"https://api.github.com/repos/fparisotto/ignition-core/issues{/number}","pulls_url":"https://api.github.com/repos/fparisotto/ignition-core/pulls{/number}","milestones_url":"https://api.github.com/repos/fparisotto/ignition-core/milestones{/number}","notifications_url":"https://api.github.com/repos/fparisotto/ignition-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fparisotto/ignition-core/labels{/name}","releases_url":"https://api.github.com/repos/fparisotto/ignition-core/releases{/id}","created_at":"2015-01-29T14:48:59Z","updated_at":"2015-03-06T12:38:32Z","pushed_at":"2015-09-09T19:02:11Z","git_url":"git://github.com/fparisotto/ignition-core.git","ssh_url":"git@github.com:fparisotto/ignition-core.git","clone_url":"https://github.com/fparisotto/ignition-core.git","svn_url":"https://github.com/fparisotto/ignition-core","homepage":null,"size":583,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"chaordic:master","ref":"master","sha":"5072a9cd1f079a53b40667210c38c1d16980fe41","user":{"login":"chaordic","id":1434501,"avatar_url":"https://avatars.githubusercontent.com/u/1434501?v=3","gravatar_id":"","url":"https://api.github.com/users/chaordic","html_url":"https://github.com/chaordic","followers_url":"https://api.github.com/users/chaordic/followers","following_url":"https://api.github.com/users/chaordic/following{/other_user}","gists_url":"https://api.github.com/users/chaordic/gists{/gist_id}","starred_url":"https://api.github.com/users/chaordic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaordic/subscriptions","organizations_url":"https://api.github.com/users/chaordic/orgs","repos_url":"https://api.github.com/users/chaordic/repos","events_url":"https://api.github.com/users/chaordic/events{/privacy}","received_events_url":"https://api.github.com/users/chaordic/received_events","type":"Organization","site_admin":false},"repo":{"id":21045905,"name":"ignition-core","full_name":"chaordic/ignition-core","owner":{"login":"chaordic","id":1434501,"avatar_url":"https://avatars.githubusercontent.com/u/1434501?v=3","gravatar_id":"","url":"https://api.github.com/users/chaordic","html_url":"https://github.com/chaordic","followers_url":"https://api.github.com/users/chaordic/followers","following_url":"https://api.github.com/users/chaordic/following{/other_user}","gists_url":"https://api.github.com/users/chaordic/gists{/gist_id}","starred_url":"https://api.github.com/users/chaordic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chaordic/subscriptions","organizations_url":"https://api.github.com/users/chaordic/orgs","repos_url":"https://api.github.com/users/chaordic/repos","events_url":"https://api.github.com/users/chaordic/events{/privacy}","received_events_url":"https://api.github.com/users/chaordic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chaordic/ignition-core","description":"Ignition-core","fork":true,"url":"https://api.github.com/repos/chaordic/ignition-core","forks_url":"https://api.github.com/repos/chaordic/ignition-core/forks","keys_url":"https://api.github.com/repos/chaordic/ignition-core/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chaordic/ignition-core/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chaordic/ignition-core/teams","hooks_url":"https://api.github.com/repos/chaordic/ignition-core/hooks","issue_events_url":"https://api.github.com/repos/chaordic/ignition-core/issues/events{/number}","events_url":"https://api.github.com/repos/chaordic/ignition-core/events","assignees_url":"https://api.github.com/repos/chaordic/ignition-core/assignees{/user}","branches_url":"https://api.github.com/repos/chaordic/ignition-core/branches{/branch}","tags_url":"https://api.github.com/repos/chaordic/ignition-core/tags","blobs_url":"https://api.github.com/repos/chaordic/ignition-core/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chaordic/ignition-core/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chaordic/ignition-core/git/refs{/sha}","trees_url":"https://api.github.com/repos/chaordic/ignition-core/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chaordic/ignition-core/statuses/{sha}","languages_url":"https://api.github.com/repos/chaordic/ignition-core/languages","stargazers_url":"https://api.github.com/repos/chaordic/ignition-core/stargazers","contributors_url":"https://api.github.com/repos/chaordic/ignition-core/contributors","subscribers_url":"https://api.github.com/repos/chaordic/ignition-core/subscribers","subscription_url":"https://api.github.com/repos/chaordic/ignition-core/subscription","commits_url":"https://api.github.com/repos/chaordic/ignition-core/commits{/sha}","git_commits_url":"https://api.github.com/repos/chaordic/ignition-core/git/commits{/sha}","comments_url":"https://api.github.com/repos/chaordic/ignition-core/comments{/number}","issue_comment_url":"https://api.github.com/repos/chaordic/ignition-core/issues/comments{/number}","contents_url":"https://api.github.com/repos/chaordic/ignition-core/contents/{+path}","compare_url":"https://api.github.com/repos/chaordic/ignition-core/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chaordic/ignition-core/merges","archive_url":"https://api.github.com/repos/chaordic/ignition-core/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chaordic/ignition-core/downloads","issues_url":"https://api.github.com/repos/chaordic/ignition-core/issues{/number}","pulls_url":"https://api.github.com/repos/chaordic/ignition-core/pulls{/number}","milestones_url":"https://api.github.com/repos/chaordic/ignition-core/milestones{/number}","notifications_url":"https://api.github.com/repos/chaordic/ignition-core/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chaordic/ignition-core/labels{/name}","releases_url":"https://api.github.com/repos/chaordic/ignition-core/releases{/id}","created_at":"2014-06-20T17:15:13Z","updated_at":"2015-05-08T19:08:16Z","pushed_at":"2015-09-11T20:27:16Z","git_url":"git://github.com/chaordic/ignition-core.git","ssh_url":"git@github.com:chaordic/ignition-core.git","clone_url":"https://github.com/chaordic/ignition-core.git","svn_url":"https://github.com/chaordic/ignition-core","homepage":null,"size":1312,"stargazers_count":1,"watchers_count":1,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chaordic/ignition-core/pulls/54"},"html":{"href":"https://github.com/chaordic/ignition-core/pull/54"},"issue":{"href":"https://api.github.com/repos/chaordic/ignition-core/issues/54"},"comments":{"href":"https://api.github.com/repos/chaordic/ignition-core/issues/54/comments"},"review_comments":{"href":"https://api.github.com/repos/chaordic/ignition-core/pulls/54/comments"},"review_comment":{"href":"https://api.github.com/repos/chaordic/ignition-core/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chaordic/ignition-core/pulls/54/commits"},"statuses":{"href":"https://api.github.com/repos/chaordic/ignition-core/statuses/056b4f82f6e91de5bdf3ebab53a8f82886e9bcac"}}}}