{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/36017650","id":36017650,"diff_hunk":"@@ -352,6 +351,177 @@ public int indexOf(UTF8String v, int start) {\n     return -1;\n   }\n \n+  private enum ByteType {FIRSTBYTE, MIDBYTE, SINGLEBYTECHAR};\n+\n+  private ByteType checkByteType(byte b) {\n+    int firstTwoBits = (b >>> 6) & 0x03;\n+    if (firstTwoBits == 3) {\n+       return ByteType.FIRSTBYTE;\n+     } else if (firstTwoBits == 2) {\n+      return ByteType.MIDBYTE;\n+    } else {\n+      return ByteType.SINGLEBYTECHAR;\n+    }\n+  }\n+\n+  /**\n+   * Return the first byte position for a given byte which shared the same code point.\n+   * @param bytePos any byte within the code point\n+   * @return the first byte position of a given code point, throw exception if not a valid UTF8 str\n+   */\n+  private int firstOfCurrentCodePoint(int bytePos) {\n+    while (bytePos >= 0) {\n+      ByteType byteType = checkByteType(getByte(bytePos));\n+      if (ByteType.FIRSTBYTE == byteType || ByteType.SINGLEBYTECHAR == byteType) {\n+        return bytePos;\n+      }\n+      bytePos--;\n+    }\n+    throw new RuntimeException(\"Invalid UTF8 string: \" + toString());\n+  }\n+\n+  // Locate to the start position in byte for a given code point\n+  private int firstByteIndex(int startByteIndex, int startPointIndex, int codePoint) {\n+    int i = startByteIndex; // position in byte\n+    int c = startPointIndex; // position in character\n+    while (i < numBytes && c < codePoint) {\n+      i += numBytesForFirstByte(getByte(i));\n+      c += 1;\n+    }\n+    if (i > numBytes) {\n+      throw new StringIndexOutOfBoundsException(codePoint);\n+    }\n+    return i;\n+  }\n+\n+  // Locate to the last position in byte for a given code point\n+  private int lastByteIndex(int codePoint) {\n+    int i = firstByteIndex(0, 0, codePoint);\n+    return i + numBytesForFirstByte(getByte(i)) - 1;\n+  }\n+\n+  /**\n+   * Returns the index within this string of the last occurrence of the\n+   * specified substring, searching backward starting at the specified index.\n+   * @param v the substring to search for.\n+   * @param startCodePoint the index to start search from\n+   * @return the index of the last occurrence of the specified substring,\n+   *         searching backward from the specified index,\n+   *         or {@code -1} if there is no such occurrence.\n+   */\n+  public int lastIndexOf(UTF8String v, int startCodePoint) {","path":"unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java","position":120,"original_position":120,"commit_id":"515519bebbec5a46de0789ea2ec82f448be0e8e8","original_commit_id":"515519bebbec5a46de0789ea2ec82f448be0e8e8","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"Should this be protected? (for tests)","created_at":"2015-07-31T21:19:47Z","updated_at":"2015-07-31T21:19:47Z","html_url":"https://github.com/apache/spark/pull/7533#discussion_r36017650","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/7533","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/36017650"},"html":{"href":"https://github.com/apache/spark/pull/7533#discussion_r36017650"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/7533"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/7533","id":40330492,"html_url":"https://github.com/apache/spark/pull/7533","diff_url":"https://github.com/apache/spark/pull/7533.diff","patch_url":"https://github.com/apache/spark/pull/7533.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/7533","number":7533,"state":"open","locked":false,"title":"[SPARK-8264][SQL]add substring_index function","user":{"login":"zhichao-li","id":2662017,"avatar_url":"https://avatars.githubusercontent.com/u/2662017?v=3","gravatar_id":"","url":"https://api.github.com/users/zhichao-li","html_url":"https://github.com/zhichao-li","followers_url":"https://api.github.com/users/zhichao-li/followers","following_url":"https://api.github.com/users/zhichao-li/following{/other_user}","gists_url":"https://api.github.com/users/zhichao-li/gists{/gist_id}","starred_url":"https://api.github.com/users/zhichao-li/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhichao-li/subscriptions","organizations_url":"https://api.github.com/users/zhichao-li/orgs","repos_url":"https://api.github.com/users/zhichao-li/repos","events_url":"https://api.github.com/users/zhichao-li/events{/privacy}","received_events_url":"https://api.github.com/users/zhichao-li/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-20T08:14:43Z","updated_at":"2015-07-31T21:19:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ab157a0eeeca8a1bfdc839e5402d34b64e708b6e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/7533/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/7533/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/7533/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/515519bebbec5a46de0789ea2ec82f448be0e8e8","head":{"label":"zhichao-li:substrindex","ref":"substrindex","sha":"515519bebbec5a46de0789ea2ec82f448be0e8e8","user":{"login":"zhichao-li","id":2662017,"avatar_url":"https://avatars.githubusercontent.com/u/2662017?v=3","gravatar_id":"","url":"https://api.github.com/users/zhichao-li","html_url":"https://github.com/zhichao-li","followers_url":"https://api.github.com/users/zhichao-li/followers","following_url":"https://api.github.com/users/zhichao-li/following{/other_user}","gists_url":"https://api.github.com/users/zhichao-li/gists{/gist_id}","starred_url":"https://api.github.com/users/zhichao-li/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhichao-li/subscriptions","organizations_url":"https://api.github.com/users/zhichao-li/orgs","repos_url":"https://api.github.com/users/zhichao-li/repos","events_url":"https://api.github.com/users/zhichao-li/events{/privacy}","received_events_url":"https://api.github.com/users/zhichao-li/received_events","type":"User","site_admin":false},"repo":{"id":30742930,"name":"spark","full_name":"zhichao-li/spark","owner":{"login":"zhichao-li","id":2662017,"avatar_url":"https://avatars.githubusercontent.com/u/2662017?v=3","gravatar_id":"","url":"https://api.github.com/users/zhichao-li","html_url":"https://github.com/zhichao-li","followers_url":"https://api.github.com/users/zhichao-li/followers","following_url":"https://api.github.com/users/zhichao-li/following{/other_user}","gists_url":"https://api.github.com/users/zhichao-li/gists{/gist_id}","starred_url":"https://api.github.com/users/zhichao-li/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhichao-li/subscriptions","organizations_url":"https://api.github.com/users/zhichao-li/orgs","repos_url":"https://api.github.com/users/zhichao-li/repos","events_url":"https://api.github.com/users/zhichao-li/events{/privacy}","received_events_url":"https://api.github.com/users/zhichao-li/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zhichao-li/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/zhichao-li/spark","forks_url":"https://api.github.com/repos/zhichao-li/spark/forks","keys_url":"https://api.github.com/repos/zhichao-li/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zhichao-li/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zhichao-li/spark/teams","hooks_url":"https://api.github.com/repos/zhichao-li/spark/hooks","issue_events_url":"https://api.github.com/repos/zhichao-li/spark/issues/events{/number}","events_url":"https://api.github.com/repos/zhichao-li/spark/events","assignees_url":"https://api.github.com/repos/zhichao-li/spark/assignees{/user}","branches_url":"https://api.github.com/repos/zhichao-li/spark/branches{/branch}","tags_url":"https://api.github.com/repos/zhichao-li/spark/tags","blobs_url":"https://api.github.com/repos/zhichao-li/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zhichao-li/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zhichao-li/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/zhichao-li/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zhichao-li/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/zhichao-li/spark/languages","stargazers_url":"https://api.github.com/repos/zhichao-li/spark/stargazers","contributors_url":"https://api.github.com/repos/zhichao-li/spark/contributors","subscribers_url":"https://api.github.com/repos/zhichao-li/spark/subscribers","subscription_url":"https://api.github.com/repos/zhichao-li/spark/subscription","commits_url":"https://api.github.com/repos/zhichao-li/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/zhichao-li/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/zhichao-li/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/zhichao-li/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/zhichao-li/spark/contents/{+path}","compare_url":"https://api.github.com/repos/zhichao-li/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zhichao-li/spark/merges","archive_url":"https://api.github.com/repos/zhichao-li/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zhichao-li/spark/downloads","issues_url":"https://api.github.com/repos/zhichao-li/spark/issues{/number}","pulls_url":"https://api.github.com/repos/zhichao-li/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/zhichao-li/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/zhichao-li/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zhichao-li/spark/labels{/name}","releases_url":"https://api.github.com/repos/zhichao-li/spark/releases{/id}","created_at":"2015-02-13T06:06:08Z","updated_at":"2015-04-14T06:24:38Z","pushed_at":"2015-07-31T17:40:16Z","git_url":"git://github.com/zhichao-li/spark.git","ssh_url":"git@github.com:zhichao-li/spark.git","clone_url":"https://github.com/zhichao-li/spark.git","svn_url":"https://github.com/zhichao-li/spark","homepage":null,"size":113186,"stargazers_count":0,"watchers_count":0,"language":"Scala","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:master","ref":"master","sha":"d4c7a7a3642a74ad40093c96c4bf45a62a470605","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":17165658,"name":"spark","full_name":"apache/spark","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/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-07-31T20:16:03Z","pushed_at":"2015-07-31T21:13:22Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1632513,"stargazers_count":4927,"watchers_count":4927,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4468,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":337,"forks":4468,"open_issues":337,"watchers":4927,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/7533"},"html":{"href":"https://github.com/apache/spark/pull/7533"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/7533"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/7533/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/7533/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/7533/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/515519bebbec5a46de0789ea2ec82f448be0e8e8"}}}}