{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-hawq/pulls/comments/51503825","id":51503825,"diff_hunk":"@@ -0,0 +1,281 @@\n+package org.apache.hawq.pxf.plugins.json;\n+\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,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+import java.io.IOException;\n+import java.security.InvalidParameterException;\n+import java.util.ArrayList;\n+import java.util.Iterator;\n+import java.util.List;\n+import java.util.regex.Matcher;\n+import java.util.regex.Pattern;\n+\n+import org.apache.hawq.pxf.api.OneField;\n+import org.apache.hawq.pxf.api.OneRow;\n+import org.apache.hawq.pxf.api.ReadResolver;\n+import org.apache.hawq.pxf.api.io.DataType;\n+import org.apache.hawq.pxf.api.utilities.ColumnDescriptor;\n+import org.apache.hawq.pxf.api.utilities.InputData;\n+import org.apache.hawq.pxf.api.utilities.Plugin;\n+import org.codehaus.jackson.JsonNode;\n+\n+/**\n+ * This JSON resolver for PXF will decode a given object from the {@link JsonAccessor} into a row for HAWQ. It will\n+ * decode this data into a JsonNode and walk the tree for each column. It supports normal value mapping via projections\n+ * and JSON array indexing.\n+ */\n+public class JsonResolver extends Plugin implements ReadResolver {\n+\n+\tprivate static Pattern ARRAY_PROJECTION_PATTERN = Pattern.compile(\"(.*)\\\\[([0-9]+)\\\\]\");\n+\n+\tprivate ArrayList<OneField> list = new ArrayList<OneField>();\n+\n+\tpublic JsonResolver(InputData inputData) throws Exception {\n+\t\tsuper(inputData);\n+\t}\n+\n+\t@Override\n+\tpublic List<OneField> getFields(OneRow row) throws Exception {\n+\t\tlist.clear();\n+\n+\t\t// key is a Text object\n+\t\tJsonNode root = JsonUtil.decodeLineToJsonNode(row.getData().toString());\n+\n+\t\t// if we weren't given a null object\n+\t\tif (root != null) {\n+\t\t\t// Iterate through the column definition and fetch our JSON data\n+\t\t\tfor (int i = 0; i < inputData.getColumns(); ++i) {\n+\n+\t\t\t\t// Get the current column description\n+\t\t\t\tColumnDescriptor cd = inputData.getColumn(i);\n+\t\t\t\tDataType columnType = DataType.get(cd.columnTypeCode());\n+\n+\t\t\t\t// Get the JSON projections from the column name\n+\t\t\t\t// For example, \"user.name\" turns into [\"user\",\"name\"]\n+\t\t\t\tString[] projs = cd.columnName().split(\"\\\\.\");\n+\n+\t\t\t\t// Move down the JSON path to the final name\n+\t\t\t\tJsonNode node = getPriorJsonNode(root, projs);\n+\n+\t\t\t\t// If this column is an array index, ex. \"tweet.hashtags[0]\"\n+\t\t\t\tif (isArrayIndex(projs)) {\n+\n+\t\t\t\t\t// Get the node name and index\n+\t\t\t\t\tString nodeName = getArrayName(projs);\n+\t\t\t\t\tint arrayIndex = getArrayIndex(projs);\n+\n+\t\t\t\t\t// Move to the array node\n+\t\t\t\t\tnode = node.get(nodeName);\n+\n+\t\t\t\t\t// If this node is null or missing, add a null value here\n+\t\t\t\t\tif (node == null || node.isMissingNode()) {\n+\t\t\t\t\t\taddNullField(columnType);\n+\t\t\t\t\t} else if (node.isArray()) {\n+\t\t\t\t\t\t// If the JSON node is an array, then add it to our list\n+\t\t\t\t\t\taddFieldFromJsonArray(columnType, node, arrayIndex);\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\tthrow new InvalidParameterException(nodeName + \" is not an array node\");\n+\t\t\t\t\t}\n+\t\t\t\t} else {\n+\t\t\t\t\t// This column is not an array type\n+\t\t\t\t\t// Move to the final node\n+\t\t\t\t\tnode = node.get(projs[projs.length - 1]);\n+\n+\t\t\t\t\t// If this node is null or missing, add a null value here\n+\t\t\t\t\tif (node == null || node.isMissingNode()) {\n+\t\t\t\t\t\taddNullField(columnType);\n+\t\t\t\t\t} else {\n+\t\t\t\t\t\t// Else, add the value to the record\n+\t\t\t\t\t\taddFieldFromJsonNode(columnType, node);\n+\t\t\t\t\t}\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\n+\t\treturn list;\n+\t}\n+\n+\t/**\n+\t * Iterates down the root node to the prior JSON node. This node is used\n+\t * \n+\t * @param root\n+\t * @param projs\n+\t * @return\n+\t */","path":"pxf/pxf-json/src/main/java/org/apache/hawq/pxf/plugins/json/JsonResolver.java","position":121,"original_position":121,"commit_id":"bf3451e371516bd87013506c6587d9e5ee3464b5","original_commit_id":"bf3451e371516bd87013506c6587d9e5ee3464b5","user":{"login":"hornn","id":11283944,"avatar_url":"https://avatars.githubusercontent.com/u/11283944?v=3","gravatar_id":"","url":"https://api.github.com/users/hornn","html_url":"https://github.com/hornn","followers_url":"https://api.github.com/users/hornn/followers","following_url":"https://api.github.com/users/hornn/following{/other_user}","gists_url":"https://api.github.com/users/hornn/gists{/gist_id}","starred_url":"https://api.github.com/users/hornn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hornn/subscriptions","organizations_url":"https://api.github.com/users/hornn/orgs","repos_url":"https://api.github.com/users/hornn/repos","events_url":"https://api.github.com/users/hornn/events{/privacy}","received_events_url":"https://api.github.com/users/hornn/received_events","type":"User","site_admin":false},"body":"/Users/nhorn/dev/hawq/apache-hawq/pxf/pxf-json/src/main/java/org/apache/hawq/pxf/plugins/json/JsonResolver.java:122: warning - @return tag has no arguments.\r\n1 warning","created_at":"2016-02-02T00:19:23Z","updated_at":"2016-02-02T00:19:23Z","html_url":"https://github.com/apache/incubator-hawq/pull/302#discussion_r51503825","pull_request_url":"https://api.github.com/repos/apache/incubator-hawq/pulls/302","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-hawq/pulls/comments/51503825"},"html":{"href":"https://github.com/apache/incubator-hawq/pull/302#discussion_r51503825"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-hawq/pulls/302"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-hawq/pulls/302","id":57582087,"html_url":"https://github.com/apache/incubator-hawq/pull/302","diff_url":"https://github.com/apache/incubator-hawq/pull/302.diff","patch_url":"https://github.com/apache/incubator-hawq/pull/302.patch","issue_url":"https://api.github.com/repos/apache/incubator-hawq/issues/302","number":302,"state":"open","locked":false,"title":"HAWQ-178: Add JSON plugin support in code base","user":{"login":"tzolov","id":1351573,"avatar_url":"https://avatars.githubusercontent.com/u/1351573?v=3","gravatar_id":"","url":"https://api.github.com/users/tzolov","html_url":"https://github.com/tzolov","followers_url":"https://api.github.com/users/tzolov/followers","following_url":"https://api.github.com/users/tzolov/following{/other_user}","gists_url":"https://api.github.com/users/tzolov/gists{/gist_id}","starred_url":"https://api.github.com/users/tzolov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzolov/subscriptions","organizations_url":"https://api.github.com/users/tzolov/orgs","repos_url":"https://api.github.com/users/tzolov/repos","events_url":"https://api.github.com/users/tzolov/events{/privacy}","received_events_url":"https://api.github.com/users/tzolov/received_events","type":"User","site_admin":false},"body":"Add `pxf-json` and registers it along the pxf-hdfs, pxf-hive and pxf-hbase plugins.  \r\n\r\nNote: I've copied the PxfUnit so i can use the pxf-json unit testing. In log term the PxfUnit should be placed in a standalone project.\r\n\r\nPlugin has manually been tested against HAWQ-2.0.0-beta.","created_at":"2016-01-28T23:14:22Z","updated_at":"2016-02-02T00:19:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d30fe2887bf0658048d52447370e79d71f8078c1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-hawq/pulls/302/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-hawq/pulls/302/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-hawq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-hawq/issues/302/comments","statuses_url":"https://api.github.com/repos/apache/incubator-hawq/statuses/bf3451e371516bd87013506c6587d9e5ee3464b5","head":{"label":"tzolov:HAWQ-178","ref":"HAWQ-178","sha":"bf3451e371516bd87013506c6587d9e5ee3464b5","user":{"login":"tzolov","id":1351573,"avatar_url":"https://avatars.githubusercontent.com/u/1351573?v=3","gravatar_id":"","url":"https://api.github.com/users/tzolov","html_url":"https://github.com/tzolov","followers_url":"https://api.github.com/users/tzolov/followers","following_url":"https://api.github.com/users/tzolov/following{/other_user}","gists_url":"https://api.github.com/users/tzolov/gists{/gist_id}","starred_url":"https://api.github.com/users/tzolov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzolov/subscriptions","organizations_url":"https://api.github.com/users/tzolov/orgs","repos_url":"https://api.github.com/users/tzolov/repos","events_url":"https://api.github.com/users/tzolov/events{/privacy}","received_events_url":"https://api.github.com/users/tzolov/received_events","type":"User","site_admin":false},"repo":{"id":48232699,"name":"incubator-hawq","full_name":"tzolov/incubator-hawq","owner":{"login":"tzolov","id":1351573,"avatar_url":"https://avatars.githubusercontent.com/u/1351573?v=3","gravatar_id":"","url":"https://api.github.com/users/tzolov","html_url":"https://github.com/tzolov","followers_url":"https://api.github.com/users/tzolov/followers","following_url":"https://api.github.com/users/tzolov/following{/other_user}","gists_url":"https://api.github.com/users/tzolov/gists{/gist_id}","starred_url":"https://api.github.com/users/tzolov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzolov/subscriptions","organizations_url":"https://api.github.com/users/tzolov/orgs","repos_url":"https://api.github.com/users/tzolov/repos","events_url":"https://api.github.com/users/tzolov/events{/privacy}","received_events_url":"https://api.github.com/users/tzolov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tzolov/incubator-hawq","description":"Mirror of Apache HAWQ (Incubating)","fork":true,"url":"https://api.github.com/repos/tzolov/incubator-hawq","forks_url":"https://api.github.com/repos/tzolov/incubator-hawq/forks","keys_url":"https://api.github.com/repos/tzolov/incubator-hawq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tzolov/incubator-hawq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tzolov/incubator-hawq/teams","hooks_url":"https://api.github.com/repos/tzolov/incubator-hawq/hooks","issue_events_url":"https://api.github.com/repos/tzolov/incubator-hawq/issues/events{/number}","events_url":"https://api.github.com/repos/tzolov/incubator-hawq/events","assignees_url":"https://api.github.com/repos/tzolov/incubator-hawq/assignees{/user}","branches_url":"https://api.github.com/repos/tzolov/incubator-hawq/branches{/branch}","tags_url":"https://api.github.com/repos/tzolov/incubator-hawq/tags","blobs_url":"https://api.github.com/repos/tzolov/incubator-hawq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tzolov/incubator-hawq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tzolov/incubator-hawq/git/refs{/sha}","trees_url":"https://api.github.com/repos/tzolov/incubator-hawq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tzolov/incubator-hawq/statuses/{sha}","languages_url":"https://api.github.com/repos/tzolov/incubator-hawq/languages","stargazers_url":"https://api.github.com/repos/tzolov/incubator-hawq/stargazers","contributors_url":"https://api.github.com/repos/tzolov/incubator-hawq/contributors","subscribers_url":"https://api.github.com/repos/tzolov/incubator-hawq/subscribers","subscription_url":"https://api.github.com/repos/tzolov/incubator-hawq/subscription","commits_url":"https://api.github.com/repos/tzolov/incubator-hawq/commits{/sha}","git_commits_url":"https://api.github.com/repos/tzolov/incubator-hawq/git/commits{/sha}","comments_url":"https://api.github.com/repos/tzolov/incubator-hawq/comments{/number}","issue_comment_url":"https://api.github.com/repos/tzolov/incubator-hawq/issues/comments{/number}","contents_url":"https://api.github.com/repos/tzolov/incubator-hawq/contents/{+path}","compare_url":"https://api.github.com/repos/tzolov/incubator-hawq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tzolov/incubator-hawq/merges","archive_url":"https://api.github.com/repos/tzolov/incubator-hawq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tzolov/incubator-hawq/downloads","issues_url":"https://api.github.com/repos/tzolov/incubator-hawq/issues{/number}","pulls_url":"https://api.github.com/repos/tzolov/incubator-hawq/pulls{/number}","milestones_url":"https://api.github.com/repos/tzolov/incubator-hawq/milestones{/number}","notifications_url":"https://api.github.com/repos/tzolov/incubator-hawq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tzolov/incubator-hawq/labels{/name}","releases_url":"https://api.github.com/repos/tzolov/incubator-hawq/releases{/id}","deployments_url":"https://api.github.com/repos/tzolov/incubator-hawq/deployments","created_at":"2015-12-18T11:53:23Z","updated_at":"2015-12-18T11:53:50Z","pushed_at":"2016-02-01T23:09:05Z","git_url":"git://github.com/tzolov/incubator-hawq.git","ssh_url":"git@github.com:tzolov/incubator-hawq.git","clone_url":"https://github.com/tzolov/incubator-hawq.git","svn_url":"https://github.com/tzolov/incubator-hawq","homepage":null,"size":148099,"stargazers_count":0,"watchers_count":0,"language":"C","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":"263fe46e7a567a101651187e521da130f5b186f9","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":41952293,"name":"incubator-hawq","full_name":"apache/incubator-hawq","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-hawq","description":"Mirror of Apache HAWQ (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-hawq","forks_url":"https://api.github.com/repos/apache/incubator-hawq/forks","keys_url":"https://api.github.com/repos/apache/incubator-hawq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-hawq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-hawq/teams","hooks_url":"https://api.github.com/repos/apache/incubator-hawq/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-hawq/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-hawq/events","assignees_url":"https://api.github.com/repos/apache/incubator-hawq/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-hawq/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-hawq/tags","blobs_url":"https://api.github.com/repos/apache/incubator-hawq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-hawq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-hawq/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-hawq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-hawq/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-hawq/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-hawq/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-hawq/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-hawq/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-hawq/subscription","commits_url":"https://api.github.com/repos/apache/incubator-hawq/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-hawq/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-hawq/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-hawq/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-hawq/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-hawq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-hawq/merges","archive_url":"https://api.github.com/repos/apache/incubator-hawq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-hawq/downloads","issues_url":"https://api.github.com/repos/apache/incubator-hawq/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-hawq/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-hawq/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-hawq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-hawq/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-hawq/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-hawq/deployments","created_at":"2015-09-05T07:00:05Z","updated_at":"2016-02-01T06:48:13Z","pushed_at":"2016-02-01T23:53:58Z","git_url":"git://github.com/apache/incubator-hawq.git","ssh_url":"git@github.com:apache/incubator-hawq.git","clone_url":"https://github.com/apache/incubator-hawq.git","svn_url":"https://github.com/apache/incubator-hawq","homepage":null,"size":148621,"stargazers_count":103,"watchers_count":103,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":90,"mirror_url":"git://git.apache.org/incubator-hawq.git","open_issues_count":13,"forks":90,"open_issues":13,"watchers":103,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-hawq/pulls/302"},"html":{"href":"https://github.com/apache/incubator-hawq/pull/302"},"issue":{"href":"https://api.github.com/repos/apache/incubator-hawq/issues/302"},"comments":{"href":"https://api.github.com/repos/apache/incubator-hawq/issues/302/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-hawq/pulls/302/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-hawq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-hawq/pulls/302/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-hawq/statuses/bf3451e371516bd87013506c6587d9e5ee3464b5"}}}}