{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-beam/pulls/comments/86609415","pull_request_review_id":7262373,"id":86609415,"diff_hunk":"@@ -324,3 +324,123 @@ def set_current_position(self, position):\n \n   def fraction_consumed(self):\n     return self._range_tracker.fraction_consumed()\n+\n+\n+class LexicographicKeyRangeTracker(iobase.RangeTracker):\n+  \"\"\"\n+  A range tracker that tracks progress through a lexicographically\n+  ordered keyspace of strings.\n+  \"\"\"\n+\n+  def __init__(self, start_key=None, stop_key=None):\n+    self._start_key = start_key\n+    self._stop_key = stop_key\n+    self._lock = threading.Lock()\n+    self._last_claim = None\n+\n+  def start_position(self):\n+    return self._start_key\n+\n+  def stop_position(self):\n+    return self._stop_key\n+\n+  def try_claim(self, position):  # pylint: disable=unused-argument\n+    with self._lock:\n+      if self.stop_key is None or position < self.stop_key:\n+        self._last_claim = position\n+        return True\n+\n+  def position_at_fraction(self, fraction):\n+    return self._fraction_to_key(fraction, self._start_key, self._end_key)\n+\n+  def try_split(self, position):\n+    with self._lock:\n+      if self._last_claim < position:\n+        fraction = self._key_to_fraction(\n+            position, self._start_key, self._stop_key)\n+        self._stop_key = position\n+        return position, fraction\n+      else:\n+        return None\n+\n+  def fraction_consumed(self):\n+    if self._last_claim is None:\n+      return 0\n+    else:\n+      return self._key_to_fraction(\n+          self._last_claim, self._start_key, self._stop_key)\n+\n+  @classmethod\n+  def _fraction_to_key(cls, fraction, start=None, end=None):\n+    \"\"\"\n+    Linearly interpolates a key that is lexicographically\n+    fraction of the way between start and end.\n+    \"\"\"\n+    assert 0 <= fraction <= 1, fraction\n+    if start is None:\n+      start = ''\n+    if fraction == 1:\n+      return end\n+    elif fraction == 0:\n+      return start\n+    else:\n+      if not end:","path":"sdks/python/apache_beam/io/range_trackers.py","position":64,"original_position":64,"commit_id":"2f64016dd710c2043eb6efc2584a85a1a4000c15","original_commit_id":"2f64016dd710c2043eb6efc2584a85a1a4000c15","user":{"login":"robertwb","id":486017,"avatar_url":"https://avatars.githubusercontent.com/u/486017?v=3","gravatar_id":"","url":"https://api.github.com/users/robertwb","html_url":"https://github.com/robertwb","followers_url":"https://api.github.com/users/robertwb/followers","following_url":"https://api.github.com/users/robertwb/following{/other_user}","gists_url":"https://api.github.com/users/robertwb/gists{/gist_id}","starred_url":"https://api.github.com/users/robertwb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertwb/subscriptions","organizations_url":"https://api.github.com/users/robertwb/orgs","repos_url":"https://api.github.com/users/robertwb/repos","events_url":"https://api.github.com/users/robertwb/events{/privacy}","received_events_url":"https://api.github.com/users/robertwb/received_events","type":"User","site_admin":false},"body":"Actually, I just implemented this based on an idea I had on the plane coming back from MTV. But looking at the implementation in Java, it's quite similar, though Python's bigints are more convenient to deal with than Java's and I just use hex to convert (as this isn't performance critical). ","created_at":"2016-11-04T18:44:53Z","updated_at":"2016-11-04T18:44:53Z","html_url":"https://github.com/apache/incubator-beam/pull/1274#discussion_r86609415","pull_request_url":"https://api.github.com/repos/apache/incubator-beam/pulls/1274","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/comments/86609415"},"html":{"href":"https://github.com/apache/incubator-beam/pull/1274#discussion_r86609415"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/1274"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-beam/pulls/1274","id":92229147,"html_url":"https://github.com/apache/incubator-beam/pull/1274","diff_url":"https://github.com/apache/incubator-beam/pull/1274.diff","patch_url":"https://github.com/apache/incubator-beam/pull/1274.patch","issue_url":"https://api.github.com/repos/apache/incubator-beam/issues/1274","number":1274,"state":"open","locked":false,"title":"Implement key range tracker.","user":{"login":"robertwb","id":486017,"avatar_url":"https://avatars.githubusercontent.com/u/486017?v=3","gravatar_id":"","url":"https://api.github.com/users/robertwb","html_url":"https://github.com/robertwb","followers_url":"https://api.github.com/users/robertwb/followers","following_url":"https://api.github.com/users/robertwb/following{/other_user}","gists_url":"https://api.github.com/users/robertwb/gists{/gist_id}","starred_url":"https://api.github.com/users/robertwb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertwb/subscriptions","organizations_url":"https://api.github.com/users/robertwb/orgs","repos_url":"https://api.github.com/users/robertwb/repos","events_url":"https://api.github.com/users/robertwb/events{/privacy}","received_events_url":"https://api.github.com/users/robertwb/received_events","type":"User","site_admin":false},"body":"Be sure to do all of the following to help us incorporate your contribution\r\nquickly and easily:\r\n\r\n - [ ] Make sure the PR title is formatted like:\r\n   `[BEAM-<Jira issue #>] Description of pull request`\r\n - [ ] Make sure tests pass via `mvn clean verify`. (Even better, enable\r\n       Travis-CI on your fork and ensure the whole test matrix passes).\r\n - [ ] Replace `<Jira issue #>` in the title with the actual Jira issue\r\n       number, if there is one.\r\n - [ ] If this contribution is large, please file an Apache\r\n       [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.txt).\r\n\r\n---\r\n\r\nThis will be useful for Bigtable and other key-based sources.","created_at":"2016-11-03T20:01:09Z","updated_at":"2016-11-04T18:44:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d34e4b0a694310b92c8073db88ed81e6c4351cd","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-beam/pulls/1274/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-beam/pulls/1274/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-beam/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-beam/issues/1274/comments","statuses_url":"https://api.github.com/repos/apache/incubator-beam/statuses/2f64016dd710c2043eb6efc2584a85a1a4000c15","head":{"label":"robertwb:key-range-tracker","ref":"key-range-tracker","sha":"2f64016dd710c2043eb6efc2584a85a1a4000c15","user":{"login":"robertwb","id":486017,"avatar_url":"https://avatars.githubusercontent.com/u/486017?v=3","gravatar_id":"","url":"https://api.github.com/users/robertwb","html_url":"https://github.com/robertwb","followers_url":"https://api.github.com/users/robertwb/followers","following_url":"https://api.github.com/users/robertwb/following{/other_user}","gists_url":"https://api.github.com/users/robertwb/gists{/gist_id}","starred_url":"https://api.github.com/users/robertwb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertwb/subscriptions","organizations_url":"https://api.github.com/users/robertwb/orgs","repos_url":"https://api.github.com/users/robertwb/repos","events_url":"https://api.github.com/users/robertwb/events{/privacy}","received_events_url":"https://api.github.com/users/robertwb/received_events","type":"User","site_admin":false},"repo":{"id":54749372,"name":"incubator-beam","full_name":"robertwb/incubator-beam","owner":{"login":"robertwb","id":486017,"avatar_url":"https://avatars.githubusercontent.com/u/486017?v=3","gravatar_id":"","url":"https://api.github.com/users/robertwb","html_url":"https://github.com/robertwb","followers_url":"https://api.github.com/users/robertwb/followers","following_url":"https://api.github.com/users/robertwb/following{/other_user}","gists_url":"https://api.github.com/users/robertwb/gists{/gist_id}","starred_url":"https://api.github.com/users/robertwb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertwb/subscriptions","organizations_url":"https://api.github.com/users/robertwb/orgs","repos_url":"https://api.github.com/users/robertwb/repos","events_url":"https://api.github.com/users/robertwb/events{/privacy}","received_events_url":"https://api.github.com/users/robertwb/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/robertwb/incubator-beam","description":"Mirror of Apache Beam (Incubating)","fork":true,"url":"https://api.github.com/repos/robertwb/incubator-beam","forks_url":"https://api.github.com/repos/robertwb/incubator-beam/forks","keys_url":"https://api.github.com/repos/robertwb/incubator-beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/robertwb/incubator-beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/robertwb/incubator-beam/teams","hooks_url":"https://api.github.com/repos/robertwb/incubator-beam/hooks","issue_events_url":"https://api.github.com/repos/robertwb/incubator-beam/issues/events{/number}","events_url":"https://api.github.com/repos/robertwb/incubator-beam/events","assignees_url":"https://api.github.com/repos/robertwb/incubator-beam/assignees{/user}","branches_url":"https://api.github.com/repos/robertwb/incubator-beam/branches{/branch}","tags_url":"https://api.github.com/repos/robertwb/incubator-beam/tags","blobs_url":"https://api.github.com/repos/robertwb/incubator-beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/robertwb/incubator-beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/robertwb/incubator-beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/robertwb/incubator-beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/robertwb/incubator-beam/statuses/{sha}","languages_url":"https://api.github.com/repos/robertwb/incubator-beam/languages","stargazers_url":"https://api.github.com/repos/robertwb/incubator-beam/stargazers","contributors_url":"https://api.github.com/repos/robertwb/incubator-beam/contributors","subscribers_url":"https://api.github.com/repos/robertwb/incubator-beam/subscribers","subscription_url":"https://api.github.com/repos/robertwb/incubator-beam/subscription","commits_url":"https://api.github.com/repos/robertwb/incubator-beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/robertwb/incubator-beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/robertwb/incubator-beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/robertwb/incubator-beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/robertwb/incubator-beam/contents/{+path}","compare_url":"https://api.github.com/repos/robertwb/incubator-beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/robertwb/incubator-beam/merges","archive_url":"https://api.github.com/repos/robertwb/incubator-beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/robertwb/incubator-beam/downloads","issues_url":"https://api.github.com/repos/robertwb/incubator-beam/issues{/number}","pulls_url":"https://api.github.com/repos/robertwb/incubator-beam/pulls{/number}","milestones_url":"https://api.github.com/repos/robertwb/incubator-beam/milestones{/number}","notifications_url":"https://api.github.com/repos/robertwb/incubator-beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/robertwb/incubator-beam/labels{/name}","releases_url":"https://api.github.com/repos/robertwb/incubator-beam/releases{/id}","deployments_url":"https://api.github.com/repos/robertwb/incubator-beam/deployments","created_at":"2016-03-25T21:47:36Z","updated_at":"2016-03-25T21:47:39Z","pushed_at":"2016-11-03T21:37:47Z","git_url":"git://github.com/robertwb/incubator-beam.git","ssh_url":"git@github.com:robertwb/incubator-beam.git","clone_url":"https://github.com/robertwb/incubator-beam.git","svn_url":"https://github.com/robertwb/incubator-beam","homepage":null,"size":22370,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:python-sdk","ref":"python-sdk","sha":"96c2286757074aed9e0f2006b8088519a16f0324","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":50904245,"name":"incubator-beam","full_name":"apache/incubator-beam","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/incubator-beam","description":"Mirror of Apache Beam (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-beam","forks_url":"https://api.github.com/repos/apache/incubator-beam/forks","keys_url":"https://api.github.com/repos/apache/incubator-beam/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-beam/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-beam/teams","hooks_url":"https://api.github.com/repos/apache/incubator-beam/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-beam/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-beam/events","assignees_url":"https://api.github.com/repos/apache/incubator-beam/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-beam/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-beam/tags","blobs_url":"https://api.github.com/repos/apache/incubator-beam/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-beam/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-beam/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-beam/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-beam/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-beam/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-beam/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-beam/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-beam/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-beam/subscription","commits_url":"https://api.github.com/repos/apache/incubator-beam/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-beam/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-beam/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-beam/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-beam/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-beam/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-beam/merges","archive_url":"https://api.github.com/repos/apache/incubator-beam/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-beam/downloads","issues_url":"https://api.github.com/repos/apache/incubator-beam/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-beam/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-beam/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-beam/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-beam/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-beam/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-beam/deployments","created_at":"2016-02-02T08:00:06Z","updated_at":"2016-11-04T15:26:45Z","pushed_at":"2016-11-04T18:33:07Z","git_url":"git://github.com/apache/incubator-beam.git","ssh_url":"git@github.com:apache/incubator-beam.git","clone_url":"https://github.com/apache/incubator-beam.git","svn_url":"https://github.com/apache/incubator-beam","homepage":null,"size":33747,"stargazers_count":419,"watchers_count":419,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":257,"mirror_url":"git://git.apache.org/incubator-beam.git","open_issues_count":62,"forks":257,"open_issues":62,"watchers":419,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/1274"},"html":{"href":"https://github.com/apache/incubator-beam/pull/1274"},"issue":{"href":"https://api.github.com/repos/apache/incubator-beam/issues/1274"},"comments":{"href":"https://api.github.com/repos/apache/incubator-beam/issues/1274/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/1274/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-beam/pulls/1274/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-beam/statuses/2f64016dd710c2043eb6efc2584a85a1a4000c15"}}}}
{"actor":{"display_login":"robertwb"}}