{"action":"created","comment":{"url":"https://api.github.com/repos/apache/storm/pulls/comments/86189092","pull_request_review_id":6858940,"id":86189092,"diff_hunk":"@@ -0,0 +1,100 @@\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.storm.sql.runtime.utils;\n+\n+import static org.apache.commons.lang.StringUtils.isNotEmpty;\n+\n+import com.google.common.base.Preconditions;\n+import org.apache.avro.util.Utf8;\n+import org.apache.storm.spout.Scheme;\n+import org.apache.storm.sql.runtime.IOutputSerializer;\n+import org.apache.storm.sql.runtime.serde.avro.AvroScheme;\n+import org.apache.storm.sql.runtime.serde.avro.AvroSerializer;\n+import org.apache.storm.sql.runtime.serde.json.JsonScheme;\n+import org.apache.storm.sql.runtime.serde.json.JsonSerializer;\n+import org.apache.storm.utils.Utils;\n+\n+import java.util.HashMap;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Properties;\n+\n+public final class SerdeUtils {\n+    public static Scheme getScheme(String inputFormatClass, Properties properties, List<String> fieldNames) {\n+        Scheme scheme;\n+        if (isNotEmpty(inputFormatClass)) {\n+            switch (inputFormatClass) {\n+                case \"org.apache.storm.sql.runtime.serde.json.JsonScheme\" :\n+                    scheme = new JsonScheme(fieldNames);\n+                    break;\n+                case \"org.apache.storm.sql.runtime.serde.avro.AvroScheme\" :\n+                    String schemaString = properties.getProperty(\"avro.schema\");\n+                    Preconditions.checkArgument(isNotEmpty(schemaString), \"avro.schema can not be empty\");\n+                    scheme = new AvroScheme(schemaString, fieldNames);\n+                    break;\n+                default:\n+                    scheme = Utils.newInstance(inputFormatClass);\n+            }\n+        } else {\n+            //use JsonScheme as the default scheme\n+            scheme = new JsonScheme(fieldNames);\n+        }\n+        return scheme;\n+    }\n+\n+    public static IOutputSerializer getSerializer(String outputFormatClass, Properties properties, List<String> fieldNames) {\n+        IOutputSerializer serializer;\n+        if (isNotEmpty(outputFormatClass)) {\n+            switch (outputFormatClass) {\n+                case \"org.apache.storm.sql.runtime.serde.json.JsonSerializer\" :\n+                    serializer = new JsonSerializer(fieldNames);\n+                    break;\n+                case \"org.apache.storm.sql.runtime.serde.avro.AvroSerializer\" :\n+                    String schemaString = properties.getProperty(\"avro.schema\");\n+                    Preconditions.checkArgument(isNotEmpty(schemaString), \"avro.schema can not be empty\");\n+                    serializer = new AvroSerializer(schemaString, fieldNames);\n+                    break;\n+                default:\n+                    serializer = Utils.newInstance(outputFormatClass);\n+            }\n+        } else {\n+            //use JsonSerializer as the default serializer\n+            serializer = new JsonSerializer(fieldNames);\n+        }\n+        return serializer;\n+    }\n+\n+    public static Map convertAvroUtf8Map(Map<Object, Object> value) {\n+        Map<Object, Object> map = new HashMap<>();\n+        for (Map.Entry<Object, Object> entry : value.entrySet()) {\n+            // Avro only allows maps with Strings for keys, so we only have to worry\n+            // about deserializing the values\n+            Object key = entry.getKey().toString();","path":"external/sql/storm-sql-runtime/src/jvm/org/apache/storm/sql/runtime/utils/SerdeUtils.java","position":87,"original_position":87,"commit_id":"ad599b48b71db3125e9bd61d75b7b6dec5f499d3","original_commit_id":"ad599b48b71db3125e9bd61d75b7b6dec5f499d3","user":{"login":"sachingsachin","id":6510635,"avatar_url":"https://avatars.githubusercontent.com/u/6510635?v=3","gravatar_id":"","url":"https://api.github.com/users/sachingsachin","html_url":"https://github.com/sachingsachin","followers_url":"https://api.github.com/users/sachingsachin/followers","following_url":"https://api.github.com/users/sachingsachin/following{/other_user}","gists_url":"https://api.github.com/users/sachingsachin/gists{/gist_id}","starred_url":"https://api.github.com/users/sachingsachin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sachingsachin/subscriptions","organizations_url":"https://api.github.com/users/sachingsachin/orgs","repos_url":"https://api.github.com/users/sachingsachin/repos","events_url":"https://api.github.com/users/sachingsachin/events{/privacy}","received_events_url":"https://api.github.com/users/sachingsachin/received_events","type":"User","site_admin":false},"body":"Avro supports non-string maps too. So conversion to string might be incorrect in those cases.","created_at":"2016-11-02T16:50:58Z","updated_at":"2016-11-02T16:50:58Z","html_url":"https://github.com/apache/storm/pull/1751#discussion_r86189092","pull_request_url":"https://api.github.com/repos/apache/storm/pulls/1751","_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/comments/86189092"},"html":{"href":"https://github.com/apache/storm/pull/1751#discussion_r86189092"},"pull_request":{"href":"https://api.github.com/repos/apache/storm/pulls/1751"}}},"pull_request":{"url":"https://api.github.com/repos/apache/storm/pulls/1751","id":91545451,"html_url":"https://github.com/apache/storm/pull/1751","diff_url":"https://github.com/apache/storm/pull/1751.diff","patch_url":"https://github.com/apache/storm/pull/1751.patch","issue_url":"https://api.github.com/repos/apache/storm/issues/1751","number":1751,"state":"open","locked":false,"title":"[STORM-2172][SQL] Support Avro as input / output format","user":{"login":"vesense","id":6711230,"avatar_url":"https://avatars.githubusercontent.com/u/6711230?v=3","gravatar_id":"","url":"https://api.github.com/users/vesense","html_url":"https://github.com/vesense","followers_url":"https://api.github.com/users/vesense/followers","following_url":"https://api.github.com/users/vesense/following{/other_user}","gists_url":"https://api.github.com/users/vesense/gists{/gist_id}","starred_url":"https://api.github.com/users/vesense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vesense/subscriptions","organizations_url":"https://api.github.com/users/vesense/orgs","repos_url":"https://api.github.com/users/vesense/repos","events_url":"https://api.github.com/users/vesense/events{/privacy}","received_events_url":"https://api.github.com/users/vesense/received_events","type":"User","site_admin":false},"body":"- new AvroScheme & AvroSerializer , unit tests\n- new avro CachedSchemas\n- new SerdeUtils\n","created_at":"2016-10-31T01:20:49Z","updated_at":"2016-11-02T16:52:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1dd02f1d55f0201f2cfccfc00fb8d267226ecdfb","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/storm/pulls/1751/commits","review_comments_url":"https://api.github.com/repos/apache/storm/pulls/1751/comments","review_comment_url":"https://api.github.com/repos/apache/storm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/storm/issues/1751/comments","statuses_url":"https://api.github.com/repos/apache/storm/statuses/ad599b48b71db3125e9bd61d75b7b6dec5f499d3","head":{"label":"vesense:STORM-2172","ref":"STORM-2172","sha":"ad599b48b71db3125e9bd61d75b7b6dec5f499d3","user":{"login":"vesense","id":6711230,"avatar_url":"https://avatars.githubusercontent.com/u/6711230?v=3","gravatar_id":"","url":"https://api.github.com/users/vesense","html_url":"https://github.com/vesense","followers_url":"https://api.github.com/users/vesense/followers","following_url":"https://api.github.com/users/vesense/following{/other_user}","gists_url":"https://api.github.com/users/vesense/gists{/gist_id}","starred_url":"https://api.github.com/users/vesense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vesense/subscriptions","organizations_url":"https://api.github.com/users/vesense/orgs","repos_url":"https://api.github.com/users/vesense/repos","events_url":"https://api.github.com/users/vesense/events{/privacy}","received_events_url":"https://api.github.com/users/vesense/received_events","type":"User","site_admin":false},"repo":{"id":30167243,"name":"storm","full_name":"vesense/storm","owner":{"login":"vesense","id":6711230,"avatar_url":"https://avatars.githubusercontent.com/u/6711230?v=3","gravatar_id":"","url":"https://api.github.com/users/vesense","html_url":"https://github.com/vesense","followers_url":"https://api.github.com/users/vesense/followers","following_url":"https://api.github.com/users/vesense/following{/other_user}","gists_url":"https://api.github.com/users/vesense/gists{/gist_id}","starred_url":"https://api.github.com/users/vesense/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vesense/subscriptions","organizations_url":"https://api.github.com/users/vesense/orgs","repos_url":"https://api.github.com/users/vesense/repos","events_url":"https://api.github.com/users/vesense/events{/privacy}","received_events_url":"https://api.github.com/users/vesense/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vesense/storm","description":"Mirror of Apache Storm","fork":true,"url":"https://api.github.com/repos/vesense/storm","forks_url":"https://api.github.com/repos/vesense/storm/forks","keys_url":"https://api.github.com/repos/vesense/storm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vesense/storm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vesense/storm/teams","hooks_url":"https://api.github.com/repos/vesense/storm/hooks","issue_events_url":"https://api.github.com/repos/vesense/storm/issues/events{/number}","events_url":"https://api.github.com/repos/vesense/storm/events","assignees_url":"https://api.github.com/repos/vesense/storm/assignees{/user}","branches_url":"https://api.github.com/repos/vesense/storm/branches{/branch}","tags_url":"https://api.github.com/repos/vesense/storm/tags","blobs_url":"https://api.github.com/repos/vesense/storm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vesense/storm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vesense/storm/git/refs{/sha}","trees_url":"https://api.github.com/repos/vesense/storm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vesense/storm/statuses/{sha}","languages_url":"https://api.github.com/repos/vesense/storm/languages","stargazers_url":"https://api.github.com/repos/vesense/storm/stargazers","contributors_url":"https://api.github.com/repos/vesense/storm/contributors","subscribers_url":"https://api.github.com/repos/vesense/storm/subscribers","subscription_url":"https://api.github.com/repos/vesense/storm/subscription","commits_url":"https://api.github.com/repos/vesense/storm/commits{/sha}","git_commits_url":"https://api.github.com/repos/vesense/storm/git/commits{/sha}","comments_url":"https://api.github.com/repos/vesense/storm/comments{/number}","issue_comment_url":"https://api.github.com/repos/vesense/storm/issues/comments{/number}","contents_url":"https://api.github.com/repos/vesense/storm/contents/{+path}","compare_url":"https://api.github.com/repos/vesense/storm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vesense/storm/merges","archive_url":"https://api.github.com/repos/vesense/storm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vesense/storm/downloads","issues_url":"https://api.github.com/repos/vesense/storm/issues{/number}","pulls_url":"https://api.github.com/repos/vesense/storm/pulls{/number}","milestones_url":"https://api.github.com/repos/vesense/storm/milestones{/number}","notifications_url":"https://api.github.com/repos/vesense/storm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vesense/storm/labels{/name}","releases_url":"https://api.github.com/repos/vesense/storm/releases{/id}","deployments_url":"https://api.github.com/repos/vesense/storm/deployments","created_at":"2015-02-02T02:07:13Z","updated_at":"2016-10-27T08:35:12Z","pushed_at":"2016-11-02T15:04:38Z","git_url":"git://github.com/vesense/storm.git","ssh_url":"git@github.com:vesense/storm.git","clone_url":"https://github.com/vesense/storm.git","svn_url":"https://github.com/vesense/storm","homepage":null,"size":109856,"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:master","ref":"master","sha":"891134926d4e223fa1140c0ebef1613deb2e3c18","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":14135470,"name":"storm","full_name":"apache/storm","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/storm","description":"Mirror of Apache Storm","fork":false,"url":"https://api.github.com/repos/apache/storm","forks_url":"https://api.github.com/repos/apache/storm/forks","keys_url":"https://api.github.com/repos/apache/storm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/storm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/storm/teams","hooks_url":"https://api.github.com/repos/apache/storm/hooks","issue_events_url":"https://api.github.com/repos/apache/storm/issues/events{/number}","events_url":"https://api.github.com/repos/apache/storm/events","assignees_url":"https://api.github.com/repos/apache/storm/assignees{/user}","branches_url":"https://api.github.com/repos/apache/storm/branches{/branch}","tags_url":"https://api.github.com/repos/apache/storm/tags","blobs_url":"https://api.github.com/repos/apache/storm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/storm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/storm/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/storm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/storm/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/storm/languages","stargazers_url":"https://api.github.com/repos/apache/storm/stargazers","contributors_url":"https://api.github.com/repos/apache/storm/contributors","subscribers_url":"https://api.github.com/repos/apache/storm/subscribers","subscription_url":"https://api.github.com/repos/apache/storm/subscription","commits_url":"https://api.github.com/repos/apache/storm/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/storm/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/storm/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/storm/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/storm/contents/{+path}","compare_url":"https://api.github.com/repos/apache/storm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/storm/merges","archive_url":"https://api.github.com/repos/apache/storm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/storm/downloads","issues_url":"https://api.github.com/repos/apache/storm/issues{/number}","pulls_url":"https://api.github.com/repos/apache/storm/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/storm/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/storm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/storm/labels{/name}","releases_url":"https://api.github.com/repos/apache/storm/releases{/id}","deployments_url":"https://api.github.com/repos/apache/storm/deployments","created_at":"2013-11-05T08:00:14Z","updated_at":"2016-11-02T16:27:00Z","pushed_at":"2016-11-02T08:08:01Z","git_url":"git://github.com/apache/storm.git","ssh_url":"git@github.com:apache/storm.git","clone_url":"https://github.com/apache/storm.git","svn_url":"https://github.com/apache/storm","homepage":null,"size":177160,"stargazers_count":3649,"watchers_count":3649,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2740,"mirror_url":"git://git.apache.org/storm.git","open_issues_count":131,"forks":2740,"open_issues":131,"watchers":3649,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/1751"},"html":{"href":"https://github.com/apache/storm/pull/1751"},"issue":{"href":"https://api.github.com/repos/apache/storm/issues/1751"},"comments":{"href":"https://api.github.com/repos/apache/storm/issues/1751/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/storm/pulls/1751/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/storm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/storm/pulls/1751/commits"},"statuses":{"href":"https://api.github.com/repos/apache/storm/statuses/ad599b48b71db3125e9bd61d75b7b6dec5f499d3"}}}}
{"actor":{"display_login":"sachingsachin"}}