{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/comments/35486212","id":35486212,"diff_hunk":"@@ -87,36 +89,51 @@ private String getData(String msg) {\n     if (msg == null) {\n       return null;\n     }\n-\n-    Type[] types = Type.values();\n-    for (Type t : types) {\n-      String magic = \"%\" + t.name().toLowerCase();\n-      if (msg.startsWith(magic + \" \") || msg.startsWith(magic + \"\\n\")) {\n-        int magicLength = magic.length() + 1;\n-        if (msg.length() > magicLength) {\n-          return msg.substring(magicLength);\n-        } else {\n-          return \"\";\n-        }\n-      }\n+    Type[] types = type.values();\n+    TreeMap<Integer, Type> typesLastIndexInMsg = buildIndexMap(msg);\n+    if (typesLastIndexInMsg.size() == 0) {\n+      return msg;\n+    } else {\n+      Map.Entry<Integer, Type> lastType = typesLastIndexInMsg.lastEntry();\n+      int magicLength = lastType.getValue().name().length() + 1; //add 1 for the %\n+      int subStringPos = magicLength + lastType.getKey() + 1; // 1 for the last \\w after magic","path":"zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterResult.java","position":null,"original_position":32,"commit_id":"29470ce2073d42fefe8fa3316e98f1e2bfc68777","original_commit_id":"3ef1584eaa3e6988ae979cdb2fb2b1c1172e5e85","user":{"login":"eranwitkon","id":2227083,"avatar_url":"https://avatars.githubusercontent.com/u/2227083?v=3","gravatar_id":"","url":"https://api.github.com/users/eranwitkon","html_url":"https://github.com/eranwitkon","followers_url":"https://api.github.com/users/eranwitkon/followers","following_url":"https://api.github.com/users/eranwitkon/following{/other_user}","gists_url":"https://api.github.com/users/eranwitkon/gists{/gist_id}","starred_url":"https://api.github.com/users/eranwitkon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eranwitkon/subscriptions","organizations_url":"https://api.github.com/users/eranwitkon/orgs","repos_url":"https://api.github.com/users/eranwitkon/repos","events_url":"https://api.github.com/users/eranwitkon/events{/privacy}","received_events_url":"https://api.github.com/users/eranwitkon/received_events","type":"User","site_admin":false},"body":"Thanks for the question.\n1) I fixed the comments to be more clear\n2) a msg with only % will not get to that point as if\n(typesLastIndexInMsg.size() == 0) which means we return  return msg;\n3) added test cases for this in unit test\n\nEran\n\nOn Sat, Jul 25, 2015 at 10:16 PM Felix Cheung <notifications@github.com>\nwrote:\n\n> In\n> zeppelin-interpreter/src/main/java/org/apache/zeppelin/interpreter/InterpreterResult.java\n> <https://github.com/apache/incubator-zeppelin/pull/164#discussion_r35485972>\n> :\n>\n> > -      if (msg.startsWith(magic + \" \") || msg.startsWith(magic + \"\\n\")) {\n> > -        int magicLength = magic.length() + 1;\n> > -        if (msg.length() > magicLength) {\n> > -          return msg.substring(magicLength);\n> > -        } else {\n> > -          return \"\";\n> > -        }\n> > -      }\n> > +    Type[] types = type.values();\n> > +    TreeMap<Integer, Type> typesLastIndexInMsg = buildIndexMap(msg);\n> > +    if (typesLastIndexInMsg.size() == 0) {\n> > +      return msg;\n> > +    } else {\n> > +      Map.Entry<Integer, Type> lastType = typesLastIndexInMsg.lastEntry();\n> > +      int magicLength = lastType.getValue().name().length() + 1; //add 1 for the %\n> > +      int subStringPos = magicLength + lastType.getKey() + 1; // 1 for the last \\w after magic\n>\n> \\w? do you mean newline or regex:\\w?\n> if latter, what if someone types \"%\" - ie. no character following %\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/apache/incubator-zeppelin/pull/164/files#r35485972>.\n>\n","created_at":"2015-07-25T19:43:10Z","updated_at":"2015-07-25T19:43:10Z","html_url":"https://github.com/apache/incubator-zeppelin/pull/164#discussion_r35486212","pull_request_url":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/comments/35486212"},"html":{"href":"https://github.com/apache/incubator-zeppelin/pull/164#discussion_r35486212"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164","id":40664140,"html_url":"https://github.com/apache/incubator-zeppelin/pull/164","diff_url":"https://github.com/apache/incubator-zeppelin/pull/164.diff","patch_url":"https://github.com/apache/incubator-zeppelin/pull/164.patch","issue_url":"https://api.github.com/repos/apache/incubator-zeppelin/issues/164","number":164,"state":"open","locked":false,"title":"Improve magic display system","user":{"login":"eranwitkon","id":2227083,"avatar_url":"https://avatars.githubusercontent.com/u/2227083?v=3","gravatar_id":"","url":"https://api.github.com/users/eranwitkon","html_url":"https://github.com/eranwitkon","followers_url":"https://api.github.com/users/eranwitkon/followers","following_url":"https://api.github.com/users/eranwitkon/following{/other_user}","gists_url":"https://api.github.com/users/eranwitkon/gists{/gist_id}","starred_url":"https://api.github.com/users/eranwitkon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eranwitkon/subscriptions","organizations_url":"https://api.github.com/users/eranwitkon/orgs","repos_url":"https://api.github.com/users/eranwitkon/repos","events_url":"https://api.github.com/users/eranwitkon/events{/privacy}","received_events_url":"https://api.github.com/users/eranwitkon/received_events","type":"User","site_admin":false},"body":"I have changed the InterpreterResult behavior so that if a magic word is detected all preceding text is omitted. This way we can use the display system and print out using the magic words in paragraphs such as spark.\r\nexample:\r\n```\r\nsc.parallelize(1 to 10)\r\n```\r\nwill output:\r\n```\r\nres9: org.apache.spark.rdd.RDD[Int] = ParallelCollectionRDD[2] at parallelize at <console>:24\r\n```  \r\n\r\nand mix paragraphs such as:\r\n```\r\nsc.parallelize(1 to 10)\r\nprintln(\"%table col\\tcol2\\nqwe\\t123\\n\")\r\n```\r\nwill output the expected magic table\r\n![selection_003](https://cloud.githubusercontent.com/assets/2227083/8849793/25ecf24c-314b-11e5-8136-ef689eaeb917.png)\r\n\r\nThis behavior can be later extended to handle complex types.\r\nI have also added a JUnit test for the class\r\n","created_at":"2015-07-23T12:00:31Z","updated_at":"2015-07-25T19:43:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"feaec9b355689b49026ec53267be7cdb4c612f33","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-zeppelin/issues/164/comments","statuses_url":"https://api.github.com/repos/apache/incubator-zeppelin/statuses/29470ce2073d42fefe8fa3316e98f1e2bfc68777","head":{"label":"eranwitkon:master","ref":"master","sha":"29470ce2073d42fefe8fa3316e98f1e2bfc68777","user":{"login":"eranwitkon","id":2227083,"avatar_url":"https://avatars.githubusercontent.com/u/2227083?v=3","gravatar_id":"","url":"https://api.github.com/users/eranwitkon","html_url":"https://github.com/eranwitkon","followers_url":"https://api.github.com/users/eranwitkon/followers","following_url":"https://api.github.com/users/eranwitkon/following{/other_user}","gists_url":"https://api.github.com/users/eranwitkon/gists{/gist_id}","starred_url":"https://api.github.com/users/eranwitkon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eranwitkon/subscriptions","organizations_url":"https://api.github.com/users/eranwitkon/orgs","repos_url":"https://api.github.com/users/eranwitkon/repos","events_url":"https://api.github.com/users/eranwitkon/events{/privacy}","received_events_url":"https://api.github.com/users/eranwitkon/received_events","type":"User","site_admin":false},"repo":{"id":39010921,"name":"incubator-zeppelin","full_name":"eranwitkon/incubator-zeppelin","owner":{"login":"eranwitkon","id":2227083,"avatar_url":"https://avatars.githubusercontent.com/u/2227083?v=3","gravatar_id":"","url":"https://api.github.com/users/eranwitkon","html_url":"https://github.com/eranwitkon","followers_url":"https://api.github.com/users/eranwitkon/followers","following_url":"https://api.github.com/users/eranwitkon/following{/other_user}","gists_url":"https://api.github.com/users/eranwitkon/gists{/gist_id}","starred_url":"https://api.github.com/users/eranwitkon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eranwitkon/subscriptions","organizations_url":"https://api.github.com/users/eranwitkon/orgs","repos_url":"https://api.github.com/users/eranwitkon/repos","events_url":"https://api.github.com/users/eranwitkon/events{/privacy}","received_events_url":"https://api.github.com/users/eranwitkon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/eranwitkon/incubator-zeppelin","description":"Mirror of Apache Zeppelin (Incubating)","fork":true,"url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin","forks_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/forks","keys_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/teams","hooks_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/hooks","issue_events_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/issues/events{/number}","events_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/events","assignees_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/assignees{/user}","branches_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/branches{/branch}","tags_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/tags","blobs_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/git/refs{/sha}","trees_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/statuses/{sha}","languages_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/languages","stargazers_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/stargazers","contributors_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/contributors","subscribers_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/subscribers","subscription_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/subscription","commits_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/commits{/sha}","git_commits_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/git/commits{/sha}","comments_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/comments{/number}","issue_comment_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/issues/comments{/number}","contents_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/contents/{+path}","compare_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/merges","archive_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/downloads","issues_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/issues{/number}","pulls_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/pulls{/number}","milestones_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/milestones{/number}","notifications_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/labels{/name}","releases_url":"https://api.github.com/repos/eranwitkon/incubator-zeppelin/releases{/id}","created_at":"2015-07-13T12:33:07Z","updated_at":"2015-07-13T12:33:08Z","pushed_at":"2015-07-25T19:40:39Z","git_url":"git://github.com/eranwitkon/incubator-zeppelin.git","ssh_url":"git@github.com:eranwitkon/incubator-zeppelin.git","clone_url":"https://github.com/eranwitkon/incubator-zeppelin.git","svn_url":"https://github.com/eranwitkon/incubator-zeppelin","homepage":null,"size":11414,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"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":"248a166f75605c6439b79266d0a414d2f54d6955","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":32848140,"name":"incubator-zeppelin","full_name":"apache/incubator-zeppelin","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-zeppelin","description":"Mirror of Apache Zeppelin (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-zeppelin","forks_url":"https://api.github.com/repos/apache/incubator-zeppelin/forks","keys_url":"https://api.github.com/repos/apache/incubator-zeppelin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-zeppelin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-zeppelin/teams","hooks_url":"https://api.github.com/repos/apache/incubator-zeppelin/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-zeppelin/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-zeppelin/events","assignees_url":"https://api.github.com/repos/apache/incubator-zeppelin/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-zeppelin/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-zeppelin/tags","blobs_url":"https://api.github.com/repos/apache/incubator-zeppelin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-zeppelin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-zeppelin/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-zeppelin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-zeppelin/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-zeppelin/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-zeppelin/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-zeppelin/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-zeppelin/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-zeppelin/subscription","commits_url":"https://api.github.com/repos/apache/incubator-zeppelin/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-zeppelin/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-zeppelin/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-zeppelin/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-zeppelin/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-zeppelin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-zeppelin/merges","archive_url":"https://api.github.com/repos/apache/incubator-zeppelin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-zeppelin/downloads","issues_url":"https://api.github.com/repos/apache/incubator-zeppelin/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-zeppelin/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-zeppelin/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-zeppelin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-zeppelin/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-zeppelin/releases{/id}","created_at":"2015-03-25T07:00:06Z","updated_at":"2015-07-25T03:33:50Z","pushed_at":"2015-07-25T19:40:39Z","git_url":"git://github.com/apache/incubator-zeppelin.git","ssh_url":"git@github.com:apache/incubator-zeppelin.git","clone_url":"https://github.com/apache/incubator-zeppelin.git","svn_url":"https://github.com/apache/incubator-zeppelin","homepage":null,"size":14552,"stargazers_count":530,"watchers_count":530,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":214,"mirror_url":"git://git.apache.org/incubator-zeppelin.git","open_issues_count":36,"forks":214,"open_issues":36,"watchers":530,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164"},"html":{"href":"https://github.com/apache/incubator-zeppelin/pull/164"},"issue":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/issues/164"},"comments":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/issues/164/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/pulls/164/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-zeppelin/statuses/29470ce2073d42fefe8fa3316e98f1e2bfc68777"}}}}