{"action":"created","comment":{"url":"https://api.github.com/repos/spotify/scio/pulls/comments/147793424","pull_request_review_id":72939752,"id":147793424,"diff_hunk":"@@ -0,0 +1,94 @@\n+/*\n+ * Copyright 2017 Spotify AB.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package com.spotify.scio.util\n+\n+import java.lang.{Iterable => JIterable}\n+\n+import com.google.common.collect.{AbstractIterator, Iterables}\n+import com.spotify.scio.values.SCollection\n+import org.apache.beam.sdk.transforms.DoFn.ProcessElement\n+import org.apache.beam.sdk.transforms.{DoFn, ParDo}\n+import org.apache.beam.sdk.transforms.join.{CoGbkResult, CoGroupByKey, KeyedPCollectionTuple}\n+import org.apache.beam.sdk.values.{KV, TupleTag}\n+\n+import scala.reflect.ClassTag\n+\n+private[scio] object ArtisanJoin {\n+\n+  private def cogroup[KEY: ClassTag, A: ClassTag, B: ClassTag, A1, B1]\n+  (name: String, a: SCollection[(KEY, A)], b: SCollection[(KEY, B)])\n+  (leftFn: JIterable[A] => JIterable[A1], rightFn: JIterable[B] => JIterable[B1])\n+  : SCollection[(KEY, (A1, B1))] = {\n+    val (tagA, tagB) = (new TupleTag[A](), new TupleTag[B]())\n+    val keyed = KeyedPCollectionTuple\n+      .of(tagA, a.toKV.internal)\n+      .and(tagB, b.toKV.internal)\n+      .apply(name, CoGroupByKey.create())\n+\n+    type DF = DoFn[KV[KEY, CoGbkResult], (KEY, (A1, B1))]\n+    a.context.wrap(keyed).withName(name)\n+      .applyTransform(ParDo.of(new DF {\n+        @ProcessElement\n+        private[util] def processElement(c: DF#ProcessContext): Unit = {\n+          val kv = c.element()\n+          val key = kv.getKey\n+          val result = kv.getValue\n+          val as = leftFn(result.getAll(tagA))\n+          val bs = rightFn(result.getAll(tagB))\n+          val ai = as.iterator()\n+          while (ai.hasNext) {\n+            val a = ai.next()\n+            val bi = bs.iterator()\n+            while (bi.hasNext) {\n+              c.output((key, (a, bi.next())))\n+            }\n+          }\n+        }\n+      }))\n+  }\n+\n+  def apply[KEY: ClassTag, A: ClassTag, B: ClassTag](name: String,\n+                                                     a: SCollection[(KEY, A)],\n+                                                     b: SCollection[(KEY, B)])\n+  : SCollection[(KEY, (A, B))] = cogroup(name, a, b)(identity, identity)\n+\n+  def left[KEY: ClassTag, A: ClassTag, B: ClassTag](name: String,\n+                                                    a: SCollection[(KEY, A)],\n+                                                    b: SCollection[(KEY, B)])\n+  : SCollection[(KEY, (A, Option[B]))] = cogroup(name, a, b)(identity, toOptions)\n+\n+  def right[KEY: ClassTag, A: ClassTag, B: ClassTag](name: String,\n+                                                     a: SCollection[(KEY, A)],\n+                                                     b: SCollection[(KEY, B)])\n+  : SCollection[(KEY, (Option[A], B))] = cogroup(name, a, b)(toOptions, identity)\n+\n+  def outer[KEY: ClassTag, A: ClassTag, B: ClassTag](name: String,\n+                                                     a: SCollection[(KEY, A)],\n+                                                     b: SCollection[(KEY, B)])\n+  : SCollection[(KEY, (Option[A], Option[B]))] = cogroup(name, a, b)(toOptions, toOptions)\n+\n+  private def toOptions[A](xs: JIterable[A]): JIterable[Option[A]] =\n+    if (xs.iterator().hasNext) {","path":"scio-core/src/main/scala/com/spotify/scio/util/ArtisanJoin.scala","position":86,"original_position":86,"commit_id":"5178dee30ec283e254719c15d6902e8c3049207f","original_commit_id":"5178dee30ec283e254719c15d6902e8c3049207f","user":{"login":"ravwojdyla","id":1419010,"avatar_url":"https://avatars0.githubusercontent.com/u/1419010?v=4","gravatar_id":"","url":"https://api.github.com/users/ravwojdyla","html_url":"https://github.com/ravwojdyla","followers_url":"https://api.github.com/users/ravwojdyla/followers","following_url":"https://api.github.com/users/ravwojdyla/following{/other_user}","gists_url":"https://api.github.com/users/ravwojdyla/gists{/gist_id}","starred_url":"https://api.github.com/users/ravwojdyla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ravwojdyla/subscriptions","organizations_url":"https://api.github.com/users/ravwojdyla/orgs","repos_url":"https://api.github.com/users/ravwojdyla/repos","events_url":"https://api.github.com/users/ravwojdyla/events{/privacy}","received_events_url":"https://api.github.com/users/ravwojdyla/received_events","type":"User","site_admin":false},"body":"`hasNext` = `isEmpty`?","created_at":"2017-10-30T18:29:05Z","updated_at":"2017-10-30T18:29:06Z","html_url":"https://github.com/spotify/scio/pull/901#discussion_r147793424","pull_request_url":"https://api.github.com/repos/spotify/scio/pulls/901","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/spotify/scio/pulls/comments/147793424"},"html":{"href":"https://github.com/spotify/scio/pull/901#discussion_r147793424"},"pull_request":{"href":"https://api.github.com/repos/spotify/scio/pulls/901"}}},"pull_request":{"url":"https://api.github.com/repos/spotify/scio/pulls/901","id":148654048,"html_url":"https://github.com/spotify/scio/pull/901","diff_url":"https://github.com/spotify/scio/pull/901.diff","patch_url":"https://github.com/spotify/scio/pull/901.patch","issue_url":"https://api.github.com/repos/spotify/scio/issues/901","number":901,"state":"open","locked":false,"title":"make joins artisanal","user":{"login":"nevillelyh","id":468514,"avatar_url":"https://avatars0.githubusercontent.com/u/468514?v=4","gravatar_id":"","url":"https://api.github.com/users/nevillelyh","html_url":"https://github.com/nevillelyh","followers_url":"https://api.github.com/users/nevillelyh/followers","following_url":"https://api.github.com/users/nevillelyh/following{/other_user}","gists_url":"https://api.github.com/users/nevillelyh/gists{/gist_id}","starred_url":"https://api.github.com/users/nevillelyh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nevillelyh/subscriptions","organizations_url":"https://api.github.com/users/nevillelyh/orgs","repos_url":"https://api.github.com/users/nevillelyh/repos","events_url":"https://api.github.com/users/nevillelyh/events{/privacy}","received_events_url":"https://api.github.com/users/nevillelyh/received_events","type":"User","site_admin":false},"body":null,"created_at":"2017-10-25T12:32:49Z","updated_at":"2017-10-30T18:29:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5e32083fe191a2d7211f62689fa616bed258c8c5","assignee":null,"assignees":[],"requested_reviewers":[{"login":"kanterov","id":467927,"avatar_url":"https://avatars2.githubusercontent.com/u/467927?v=4","gravatar_id":"","url":"https://api.github.com/users/kanterov","html_url":"https://github.com/kanterov","followers_url":"https://api.github.com/users/kanterov/followers","following_url":"https://api.github.com/users/kanterov/following{/other_user}","gists_url":"https://api.github.com/users/kanterov/gists{/gist_id}","starred_url":"https://api.github.com/users/kanterov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kanterov/subscriptions","organizations_url":"https://api.github.com/users/kanterov/orgs","repos_url":"https://api.github.com/users/kanterov/repos","events_url":"https://api.github.com/users/kanterov/events{/privacy}","received_events_url":"https://api.github.com/users/kanterov/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/spotify/scio/pulls/901/commits","review_comments_url":"https://api.github.com/repos/spotify/scio/pulls/901/comments","review_comment_url":"https://api.github.com/repos/spotify/scio/pulls/comments{/number}","comments_url":"https://api.github.com/repos/spotify/scio/issues/901/comments","statuses_url":"https://api.github.com/repos/spotify/scio/statuses/5178dee30ec283e254719c15d6902e8c3049207f","head":{"label":"spotify:neville/join","ref":"neville/join","sha":"5178dee30ec283e254719c15d6902e8c3049207f","user":{"login":"spotify","id":251374,"avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"repo":{"id":32946662,"name":"scio","full_name":"spotify/scio","owner":{"login":"spotify","id":251374,"avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spotify/scio","description":"A Scala API for Apache Beam and Google Cloud Dataflow.","fork":false,"url":"https://api.github.com/repos/spotify/scio","forks_url":"https://api.github.com/repos/spotify/scio/forks","keys_url":"https://api.github.com/repos/spotify/scio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spotify/scio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spotify/scio/teams","hooks_url":"https://api.github.com/repos/spotify/scio/hooks","issue_events_url":"https://api.github.com/repos/spotify/scio/issues/events{/number}","events_url":"https://api.github.com/repos/spotify/scio/events","assignees_url":"https://api.github.com/repos/spotify/scio/assignees{/user}","branches_url":"https://api.github.com/repos/spotify/scio/branches{/branch}","tags_url":"https://api.github.com/repos/spotify/scio/tags","blobs_url":"https://api.github.com/repos/spotify/scio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spotify/scio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spotify/scio/git/refs{/sha}","trees_url":"https://api.github.com/repos/spotify/scio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spotify/scio/statuses/{sha}","languages_url":"https://api.github.com/repos/spotify/scio/languages","stargazers_url":"https://api.github.com/repos/spotify/scio/stargazers","contributors_url":"https://api.github.com/repos/spotify/scio/contributors","subscribers_url":"https://api.github.com/repos/spotify/scio/subscribers","subscription_url":"https://api.github.com/repos/spotify/scio/subscription","commits_url":"https://api.github.com/repos/spotify/scio/commits{/sha}","git_commits_url":"https://api.github.com/repos/spotify/scio/git/commits{/sha}","comments_url":"https://api.github.com/repos/spotify/scio/comments{/number}","issue_comment_url":"https://api.github.com/repos/spotify/scio/issues/comments{/number}","contents_url":"https://api.github.com/repos/spotify/scio/contents/{+path}","compare_url":"https://api.github.com/repos/spotify/scio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spotify/scio/merges","archive_url":"https://api.github.com/repos/spotify/scio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spotify/scio/downloads","issues_url":"https://api.github.com/repos/spotify/scio/issues{/number}","pulls_url":"https://api.github.com/repos/spotify/scio/pulls{/number}","milestones_url":"https://api.github.com/repos/spotify/scio/milestones{/number}","notifications_url":"https://api.github.com/repos/spotify/scio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spotify/scio/labels{/name}","releases_url":"https://api.github.com/repos/spotify/scio/releases{/id}","deployments_url":"https://api.github.com/repos/spotify/scio/deployments","created_at":"2015-03-26T19:07:34Z","updated_at":"2017-10-30T10:51:45Z","pushed_at":"2017-10-30T10:34:30Z","git_url":"git://github.com/spotify/scio.git","ssh_url":"git@github.com:spotify/scio.git","clone_url":"https://github.com/spotify/scio.git","svn_url":"https://github.com/spotify/scio","homepage":"http://spotify.github.io/scio/com/spotify/scio/","size":7835,"stargazers_count":735,"watchers_count":735,"language":"Scala","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":113,"mirror_url":null,"archived":false,"open_issues_count":44,"forks":113,"open_issues":44,"watchers":735,"default_branch":"master"}},"base":{"label":"spotify:master","ref":"master","sha":"2b643c955fcfad4df7b698583eef1107f1264093","user":{"login":"spotify","id":251374,"avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"repo":{"id":32946662,"name":"scio","full_name":"spotify/scio","owner":{"login":"spotify","id":251374,"avatar_url":"https://avatars2.githubusercontent.com/u/251374?v=4","gravatar_id":"","url":"https://api.github.com/users/spotify","html_url":"https://github.com/spotify","followers_url":"https://api.github.com/users/spotify/followers","following_url":"https://api.github.com/users/spotify/following{/other_user}","gists_url":"https://api.github.com/users/spotify/gists{/gist_id}","starred_url":"https://api.github.com/users/spotify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/spotify/subscriptions","organizations_url":"https://api.github.com/users/spotify/orgs","repos_url":"https://api.github.com/users/spotify/repos","events_url":"https://api.github.com/users/spotify/events{/privacy}","received_events_url":"https://api.github.com/users/spotify/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/spotify/scio","description":"A Scala API for Apache Beam and Google Cloud Dataflow.","fork":false,"url":"https://api.github.com/repos/spotify/scio","forks_url":"https://api.github.com/repos/spotify/scio/forks","keys_url":"https://api.github.com/repos/spotify/scio/keys{/key_id}","collaborators_url":"https://api.github.com/repos/spotify/scio/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/spotify/scio/teams","hooks_url":"https://api.github.com/repos/spotify/scio/hooks","issue_events_url":"https://api.github.com/repos/spotify/scio/issues/events{/number}","events_url":"https://api.github.com/repos/spotify/scio/events","assignees_url":"https://api.github.com/repos/spotify/scio/assignees{/user}","branches_url":"https://api.github.com/repos/spotify/scio/branches{/branch}","tags_url":"https://api.github.com/repos/spotify/scio/tags","blobs_url":"https://api.github.com/repos/spotify/scio/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/spotify/scio/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/spotify/scio/git/refs{/sha}","trees_url":"https://api.github.com/repos/spotify/scio/git/trees{/sha}","statuses_url":"https://api.github.com/repos/spotify/scio/statuses/{sha}","languages_url":"https://api.github.com/repos/spotify/scio/languages","stargazers_url":"https://api.github.com/repos/spotify/scio/stargazers","contributors_url":"https://api.github.com/repos/spotify/scio/contributors","subscribers_url":"https://api.github.com/repos/spotify/scio/subscribers","subscription_url":"https://api.github.com/repos/spotify/scio/subscription","commits_url":"https://api.github.com/repos/spotify/scio/commits{/sha}","git_commits_url":"https://api.github.com/repos/spotify/scio/git/commits{/sha}","comments_url":"https://api.github.com/repos/spotify/scio/comments{/number}","issue_comment_url":"https://api.github.com/repos/spotify/scio/issues/comments{/number}","contents_url":"https://api.github.com/repos/spotify/scio/contents/{+path}","compare_url":"https://api.github.com/repos/spotify/scio/compare/{base}...{head}","merges_url":"https://api.github.com/repos/spotify/scio/merges","archive_url":"https://api.github.com/repos/spotify/scio/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/spotify/scio/downloads","issues_url":"https://api.github.com/repos/spotify/scio/issues{/number}","pulls_url":"https://api.github.com/repos/spotify/scio/pulls{/number}","milestones_url":"https://api.github.com/repos/spotify/scio/milestones{/number}","notifications_url":"https://api.github.com/repos/spotify/scio/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/spotify/scio/labels{/name}","releases_url":"https://api.github.com/repos/spotify/scio/releases{/id}","deployments_url":"https://api.github.com/repos/spotify/scio/deployments","created_at":"2015-03-26T19:07:34Z","updated_at":"2017-10-30T10:51:45Z","pushed_at":"2017-10-30T10:34:30Z","git_url":"git://github.com/spotify/scio.git","ssh_url":"git@github.com:spotify/scio.git","clone_url":"https://github.com/spotify/scio.git","svn_url":"https://github.com/spotify/scio","homepage":"http://spotify.github.io/scio/com/spotify/scio/","size":7835,"stargazers_count":735,"watchers_count":735,"language":"Scala","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":113,"mirror_url":null,"archived":false,"open_issues_count":44,"forks":113,"open_issues":44,"watchers":735,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/spotify/scio/pulls/901"},"html":{"href":"https://github.com/spotify/scio/pull/901"},"issue":{"href":"https://api.github.com/repos/spotify/scio/issues/901"},"comments":{"href":"https://api.github.com/repos/spotify/scio/issues/901/comments"},"review_comments":{"href":"https://api.github.com/repos/spotify/scio/pulls/901/comments"},"review_comment":{"href":"https://api.github.com/repos/spotify/scio/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/spotify/scio/pulls/901/commits"},"statuses":{"href":"https://api.github.com/repos/spotify/scio/statuses/5178dee30ec283e254719c15d6902e8c3049207f"}},"author_association":"OWNER"}}
{"actor":{"display_login":"ravwojdyla"}}