{"action":"created","comment":{"url":"https://api.github.com/repos/apache/drill/pulls/comments/45233299","id":45233299,"diff_hunk":"@@ -0,0 +1,123 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  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, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package org.apache.drill.exec.exception;\n+\n+import com.google.common.collect.Lists;\n+import org.apache.drill.exec.proto.UserBitShared.WarningMsg;\n+\n+import java.util.IdentityHashMap;\n+import java.util.List;\n+\n+/**\n+ * Helper class to manage warnings for FragmentContext and Foreman\n+ */\n+public class DrillWarningHelper {\n+\n+  private List<IdentityHashMap<String, WarningMsg>> warnings;\n+  private String fragmentId;\n+  int numWarnings = 0;\n+\n+  public DrillWarningHelper (String fragmentId) {\n+    this.warnings = Lists.newArrayList();\n+    this.fragmentId = fragmentId;\n+  }\n+\n+  /**\n+   * Interface for operators to add warnings\n+   * @param operatorId operator warning is coming from\n+   * @param type pre-defined warning type\n+   * @param msg custom warning message\n+   */\n+  public void addWarning (int operatorId, String type, String msg) {\n+    assert (operatorId >= 0 && type != null);\n+\n+    IdentityHashMap<String, WarningMsg> warningMap = null;\n+    if (operatorId < warnings.size()) {\n+      // we have received warnings from this operator before, go fetch it\n+      warningMap = warnings.get(operatorId);\n+    }\n+\n+    if (warningMap == null) {\n+      // first warning for this operator\n+      warningMap = new IdentityHashMap<>();\n+    }\n+\n+    WarningMsg wm = warningMap.get(type);\n+    if (wm == null) {\n+      // first warning of this type from the operator\n+      wm = WarningMsg.newBuilder()\n+          .setMessage(msg)\n+          .setCount(1)\n+          .build();\n+      numWarnings++;\n+    } else {\n+      // we have seen this type before from the operator, update it\n+      wm = wm.toBuilder()\n+          .setMessage(msg)\n+          .setCount(wm.getCount() + 1)\n+          .build();\n+    }\n+    warningMap.put(type, wm);\n+    warnings.add(operatorId, warningMap);\n+  }\n+\n+  /**\n+   * Get Unique warning code\n+   * @param operatorId\n+   * @param type\n+   * @return\n+   */\n+  public String getWarningCode (int operatorId, String type) {\n+    return operatorId + \"-\" + this.fragmentId + \"-\" + type;\n+  }\n+\n+  /**\n+   * Get flattened list of WarningMsg\n+   * @return list of WarningMsg\n+   */\n+  public List<WarningMsg> getWarnings () {\n+    List<WarningMsg> retWarnings = Lists.newArrayList();\n+    for (int opId = 0; opId < warnings.size(); opId++) {\n+      IdentityHashMap<String, WarningMsg> warning = warnings.get(opId);\n+      if (warning == null) {\n+        continue;\n+      }\n+      for (String type : warning.keySet()) {\n+        WarningMsg wm = warning.get(type);\n+        wm.toBuilder()\n+            .setWarningCode(getWarningCode(opId, type))\n+            .build();\n+        retWarnings.add(wm);\n+      }\n+    }\n+    return retWarnings;\n+  }\n+\n+  public void clearWarnings () {\n+    for (IdentityHashMap<String, WarningMsg> warning : warnings) {\n+      warning.clear();\n+    }\n+    warnings.clear();","path":"exec/java-exec/src/main/java/org/apache/drill/exec/exception/DrillWarningHelper.java","position":115,"original_position":115,"commit_id":"137059cd44ec28e8ba3bf2aa73d2c1cbcd55d604","original_commit_id":"137059cd44ec28e8ba3bf2aa73d2c1cbcd55d604","user":{"login":"sudheeshkatkam","id":3272600,"avatar_url":"https://avatars.githubusercontent.com/u/3272600?v=3","gravatar_id":"","url":"https://api.github.com/users/sudheeshkatkam","html_url":"https://github.com/sudheeshkatkam","followers_url":"https://api.github.com/users/sudheeshkatkam/followers","following_url":"https://api.github.com/users/sudheeshkatkam/following{/other_user}","gists_url":"https://api.github.com/users/sudheeshkatkam/gists{/gist_id}","starred_url":"https://api.github.com/users/sudheeshkatkam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sudheeshkatkam/subscriptions","organizations_url":"https://api.github.com/users/sudheeshkatkam/orgs","repos_url":"https://api.github.com/users/sudheeshkatkam/repos","events_url":"https://api.github.com/users/sudheeshkatkam/events{/privacy}","received_events_url":"https://api.github.com/users/sudheeshkatkam/received_events","type":"User","site_admin":false},"body":"Why isn't this clear() sufficient?","created_at":"2015-11-18T17:45:57Z","updated_at":"2015-11-18T17:45:57Z","html_url":"https://github.com/apache/drill/pull/263#discussion_r45233299","pull_request_url":"https://api.github.com/repos/apache/drill/pulls/263","_links":{"self":{"href":"https://api.github.com/repos/apache/drill/pulls/comments/45233299"},"html":{"href":"https://github.com/apache/drill/pull/263#discussion_r45233299"},"pull_request":{"href":"https://api.github.com/repos/apache/drill/pulls/263"}}},"pull_request":{"url":"https://api.github.com/repos/apache/drill/pulls/263","id":51027439,"html_url":"https://github.com/apache/drill/pull/263","diff_url":"https://github.com/apache/drill/pull/263.diff","patch_url":"https://github.com/apache/drill/pull/263.patch","issue_url":"https://api.github.com/repos/apache/drill/issues/263","number":263,"state":"open","locked":false,"title":"DRILL-4015: Update DrillClient and JDBC driver to expose warnings provided via RPC layer","user":{"login":"abhipol","id":15219028,"avatar_url":"https://avatars.githubusercontent.com/u/15219028?v=3","gravatar_id":"","url":"https://api.github.com/users/abhipol","html_url":"https://github.com/abhipol","followers_url":"https://api.github.com/users/abhipol/followers","following_url":"https://api.github.com/users/abhipol/following{/other_user}","gists_url":"https://api.github.com/users/abhipol/gists{/gist_id}","starred_url":"https://api.github.com/users/abhipol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhipol/subscriptions","organizations_url":"https://api.github.com/users/abhipol/orgs","repos_url":"https://api.github.com/users/abhipol/repos","events_url":"https://api.github.com/users/abhipol/events{/privacy}","received_events_url":"https://api.github.com/users/abhipol/received_events","type":"User","site_admin":false},"body":"surface our query warnings from operators to JDBC client as a part of query result as well as out of band warnings. Details: https://docs.google.com/document/d/1HwpD3gRbNohpse9zbm3cmLZixGn6EgapulEGrRtKlkA","created_at":"2015-11-18T00:43:26Z","updated_at":"2015-11-18T17:45:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9403d29bc67fa7b378cae63a4f8fac5d4874e36b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/drill/pulls/263/commits","review_comments_url":"https://api.github.com/repos/apache/drill/pulls/263/comments","review_comment_url":"https://api.github.com/repos/apache/drill/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/drill/issues/263/comments","statuses_url":"https://api.github.com/repos/apache/drill/statuses/137059cd44ec28e8ba3bf2aa73d2c1cbcd55d604","head":{"label":"abhipol:issues/DRILL-4015","ref":"issues/DRILL-4015","sha":"137059cd44ec28e8ba3bf2aa73d2c1cbcd55d604","user":{"login":"abhipol","id":15219028,"avatar_url":"https://avatars.githubusercontent.com/u/15219028?v=3","gravatar_id":"","url":"https://api.github.com/users/abhipol","html_url":"https://github.com/abhipol","followers_url":"https://api.github.com/users/abhipol/followers","following_url":"https://api.github.com/users/abhipol/following{/other_user}","gists_url":"https://api.github.com/users/abhipol/gists{/gist_id}","starred_url":"https://api.github.com/users/abhipol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhipol/subscriptions","organizations_url":"https://api.github.com/users/abhipol/orgs","repos_url":"https://api.github.com/users/abhipol/repos","events_url":"https://api.github.com/users/abhipol/events{/privacy}","received_events_url":"https://api.github.com/users/abhipol/received_events","type":"User","site_admin":false},"repo":{"id":45423068,"name":"drill","full_name":"abhipol/drill","owner":{"login":"abhipol","id":15219028,"avatar_url":"https://avatars.githubusercontent.com/u/15219028?v=3","gravatar_id":"","url":"https://api.github.com/users/abhipol","html_url":"https://github.com/abhipol","followers_url":"https://api.github.com/users/abhipol/followers","following_url":"https://api.github.com/users/abhipol/following{/other_user}","gists_url":"https://api.github.com/users/abhipol/gists{/gist_id}","starred_url":"https://api.github.com/users/abhipol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhipol/subscriptions","organizations_url":"https://api.github.com/users/abhipol/orgs","repos_url":"https://api.github.com/users/abhipol/repos","events_url":"https://api.github.com/users/abhipol/events{/privacy}","received_events_url":"https://api.github.com/users/abhipol/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/abhipol/drill","description":"Mirror of Apache Drill","fork":true,"url":"https://api.github.com/repos/abhipol/drill","forks_url":"https://api.github.com/repos/abhipol/drill/forks","keys_url":"https://api.github.com/repos/abhipol/drill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abhipol/drill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abhipol/drill/teams","hooks_url":"https://api.github.com/repos/abhipol/drill/hooks","issue_events_url":"https://api.github.com/repos/abhipol/drill/issues/events{/number}","events_url":"https://api.github.com/repos/abhipol/drill/events","assignees_url":"https://api.github.com/repos/abhipol/drill/assignees{/user}","branches_url":"https://api.github.com/repos/abhipol/drill/branches{/branch}","tags_url":"https://api.github.com/repos/abhipol/drill/tags","blobs_url":"https://api.github.com/repos/abhipol/drill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abhipol/drill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abhipol/drill/git/refs{/sha}","trees_url":"https://api.github.com/repos/abhipol/drill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abhipol/drill/statuses/{sha}","languages_url":"https://api.github.com/repos/abhipol/drill/languages","stargazers_url":"https://api.github.com/repos/abhipol/drill/stargazers","contributors_url":"https://api.github.com/repos/abhipol/drill/contributors","subscribers_url":"https://api.github.com/repos/abhipol/drill/subscribers","subscription_url":"https://api.github.com/repos/abhipol/drill/subscription","commits_url":"https://api.github.com/repos/abhipol/drill/commits{/sha}","git_commits_url":"https://api.github.com/repos/abhipol/drill/git/commits{/sha}","comments_url":"https://api.github.com/repos/abhipol/drill/comments{/number}","issue_comment_url":"https://api.github.com/repos/abhipol/drill/issues/comments{/number}","contents_url":"https://api.github.com/repos/abhipol/drill/contents/{+path}","compare_url":"https://api.github.com/repos/abhipol/drill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abhipol/drill/merges","archive_url":"https://api.github.com/repos/abhipol/drill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abhipol/drill/downloads","issues_url":"https://api.github.com/repos/abhipol/drill/issues{/number}","pulls_url":"https://api.github.com/repos/abhipol/drill/pulls{/number}","milestones_url":"https://api.github.com/repos/abhipol/drill/milestones{/number}","notifications_url":"https://api.github.com/repos/abhipol/drill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abhipol/drill/labels{/name}","releases_url":"https://api.github.com/repos/abhipol/drill/releases{/id}","created_at":"2015-11-02T21:25:45Z","updated_at":"2015-11-02T21:25:55Z","pushed_at":"2015-11-18T09:21:52Z","git_url":"git://github.com/abhipol/drill.git","ssh_url":"git@github.com:abhipol/drill.git","clone_url":"https://github.com/abhipol/drill.git","svn_url":"https://github.com/abhipol/drill","homepage":"","size":39342,"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":"a6a0fc37779399c936237143572ec57142e0039c","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":5683653,"name":"drill","full_name":"apache/drill","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/drill","description":"Mirror of Apache Drill","fork":false,"url":"https://api.github.com/repos/apache/drill","forks_url":"https://api.github.com/repos/apache/drill/forks","keys_url":"https://api.github.com/repos/apache/drill/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/drill/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/drill/teams","hooks_url":"https://api.github.com/repos/apache/drill/hooks","issue_events_url":"https://api.github.com/repos/apache/drill/issues/events{/number}","events_url":"https://api.github.com/repos/apache/drill/events","assignees_url":"https://api.github.com/repos/apache/drill/assignees{/user}","branches_url":"https://api.github.com/repos/apache/drill/branches{/branch}","tags_url":"https://api.github.com/repos/apache/drill/tags","blobs_url":"https://api.github.com/repos/apache/drill/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/drill/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/drill/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/drill/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/drill/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/drill/languages","stargazers_url":"https://api.github.com/repos/apache/drill/stargazers","contributors_url":"https://api.github.com/repos/apache/drill/contributors","subscribers_url":"https://api.github.com/repos/apache/drill/subscribers","subscription_url":"https://api.github.com/repos/apache/drill/subscription","commits_url":"https://api.github.com/repos/apache/drill/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/drill/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/drill/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/drill/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/drill/contents/{+path}","compare_url":"https://api.github.com/repos/apache/drill/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/drill/merges","archive_url":"https://api.github.com/repos/apache/drill/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/drill/downloads","issues_url":"https://api.github.com/repos/apache/drill/issues{/number}","pulls_url":"https://api.github.com/repos/apache/drill/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/drill/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/drill/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/drill/labels{/name}","releases_url":"https://api.github.com/repos/apache/drill/releases{/id}","created_at":"2012-09-05T07:00:26Z","updated_at":"2015-11-18T10:29:16Z","pushed_at":"2015-11-18T16:45:16Z","git_url":"git://github.com/apache/drill.git","ssh_url":"git@github.com:apache/drill.git","clone_url":"https://github.com/apache/drill.git","svn_url":"https://github.com/apache/drill","homepage":"","size":42601,"stargazers_count":513,"watchers_count":513,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":334,"mirror_url":"git://git.apache.org/incubator-drill.git","open_issues_count":55,"forks":334,"open_issues":55,"watchers":513,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/drill/pulls/263"},"html":{"href":"https://github.com/apache/drill/pull/263"},"issue":{"href":"https://api.github.com/repos/apache/drill/issues/263"},"comments":{"href":"https://api.github.com/repos/apache/drill/issues/263/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/drill/pulls/263/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/drill/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/drill/pulls/263/commits"},"statuses":{"href":"https://api.github.com/repos/apache/drill/statuses/137059cd44ec28e8ba3bf2aa73d2c1cbcd55d604"}}}}