{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-nifi/pulls/comments/34172888","id":34172888,"diff_hunk":"@@ -0,0 +1,279 @@\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+package org.apache.nifi.processors.kite;\n+\n+import java.io.IOException;\n+import java.util.List;\n+import java.util.Map;\n+\n+import org.apache.avro.Schema;\n+import org.apache.avro.Schema.Field;\n+import org.apache.avro.generic.GenericData.Record;\n+import org.apache.avro.generic.IndexedRecord;\n+import org.codehaus.jackson.JsonNode;\n+\n+import com.google.common.base.Preconditions;\n+import com.google.common.collect.Lists;\n+import com.google.common.collect.Maps;\n+\n+/**\n+ * Responsible for converting records of one Avro type to another. Supports\n+ * syntax like \"record.field\" to unpack fields and will try to do simple type\n+ * conversion.\n+ */\n+public class AvroRecordConverter {\n+\tprivate final Schema inputSchema;\n+\tprivate final Schema outputSchema;\n+\tprivate final Map<String, String> fieldMapping;\n+\n+\tpublic AvroRecordConverter(Schema inputSchema, Schema outputSchema,\n+\t\t\tJsonNode fieldMapping) {\n+\t\tthis.inputSchema = inputSchema;\n+\t\tthis.outputSchema = outputSchema;\n+\t\tthis.fieldMapping = getFieldMapping(fieldMapping);\n+\t}\n+\n+\t/**\n+\t * Converts one record to another given a input and output schema plus\n+\t * explicit mappings for certain target fields.\n+\t * \n+\t * @param record\n+\t * @param inputSchema\n+\t * @param outputSchema\n+\t * @param fieldMapping\n+\t * @return\n+\t * @throws AvroConversionException\n+\t */\n+\tpublic Record convert(Record input) throws AvroConversionException {\n+\t\tRecord result = new Record(outputSchema);\n+\t\tfor (Field outputField : outputSchema.getFields()) {\n+\t\t\tString inputFieldName = outputField.name();\n+\t\t\tif (fieldMapping.containsKey(outputField.name())) {\n+\t\t\t\tinputFieldName = fieldMapping.get(outputField.name());\n+\t\t\t}\n+\n+\t\t\tList<String> fieldParts = Lists.newArrayList(inputFieldName\n+\t\t\t\t\t.split(\"\\\\.\"));\n+\t\t\tRecord current = input;\n+\t\t\twhile (fieldParts.size() > 1) {\n+\t\t\t\t// Step into the nested records as far as needed.\n+\t\t\t\tcurrent = (Record) current.get(fieldParts.remove(0));\n+\t\t\t}\n+\n+\t\t\t// Current should now be in the right place to read the record.\n+\t\t\tField f = getFieldForName(inputFieldName, inputSchema);\n+\t\t\tObject content = getContentForName(input, inputFieldName,\n+\t\t\t\t\tinput.getSchema());\n+\t\t\tresult.put(outputField.name(),\n+\t\t\t\t\tconvertData(content, f.schema(), outputField.schema()));\n+\t\t}\n+\t\treturn result;\n+\t}\n+\n+\t/**\n+\t * @return the inputSchema\n+\t */\n+\tpublic Schema getInputSchema() {\n+\t\treturn inputSchema;\n+\t}\n+\n+\t/**\n+\t * @return the outputSchema\n+\t */\n+\tpublic Schema getOutputSchema() {\n+\t\treturn outputSchema;\n+\t}\n+\n+\t/**\n+\t * Converts the data from one schema to another. If the types are the same,\n+\t * no change will be made, but simple conversions will be attempted for\n+\t * other types.\n+\t * \n+\t * @param content\n+\t * @param inputSchema\n+\t * @param outputSchema\n+\t * @return\n+\t * @throws AvroConversionException\n+\t */\n+\tprivate Object convertData(Object content, Schema inputSchema,\n+\t\t\tSchema outputSchema) throws AvroConversionException {\n+\t\tif (content == null) {\n+\t\t\t// No conversion can happen here.\n+\t\t\treturn null;","path":"nifi/nifi-nar-bundles/nifi-kite-bundle/nifi-kite-processors/src/main/java/org/apache/nifi/processors/kite/AvroRecordConverter.java","position":118,"original_position":118,"commit_id":"d50171381f853334bb670edb5581445fdfef0e46","original_commit_id":"d50171381f853334bb670edb5581445fdfef0e46","user":{"login":"rdblue","id":87915,"avatar_url":"https://avatars.githubusercontent.com/u/87915?v=3","gravatar_id":"","url":"https://api.github.com/users/rdblue","html_url":"https://github.com/rdblue","followers_url":"https://api.github.com/users/rdblue/followers","following_url":"https://api.github.com/users/rdblue/following{/other_user}","gists_url":"https://api.github.com/users/rdblue/gists{/gist_id}","starred_url":"https://api.github.com/users/rdblue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rdblue/subscriptions","organizations_url":"https://api.github.com/users/rdblue/orgs","repos_url":"https://api.github.com/users/rdblue/repos","events_url":"https://api.github.com/users/rdblue/events{/privacy}","received_events_url":"https://api.github.com/users/rdblue/received_events","type":"User","site_admin":false},"body":"Should this check to see whether the outputSchema allows null?","created_at":"2015-07-08T17:14:46Z","updated_at":"2015-07-08T17:14:46Z","html_url":"https://github.com/apache/incubator-nifi/pull/70#discussion_r34172888","pull_request_url":"https://api.github.com/repos/apache/incubator-nifi/pulls/70","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-nifi/pulls/comments/34172888"},"html":{"href":"https://github.com/apache/incubator-nifi/pull/70#discussion_r34172888"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-nifi/pulls/70"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-nifi/pulls/70","id":39419188,"html_url":"https://github.com/apache/incubator-nifi/pull/70","diff_url":"https://github.com/apache/incubator-nifi/pull/70.diff","patch_url":"https://github.com/apache/incubator-nifi/pull/70.patch","issue_url":"https://api.github.com/repos/apache/incubator-nifi/issues/70","number":70,"state":"open","locked":false,"title":"NIFI-751 Add Processor To Convert Avro Formats","user":{"login":"jackowaya","id":450988,"avatar_url":"https://avatars.githubusercontent.com/u/450988?v=3","gravatar_id":"","url":"https://api.github.com/users/jackowaya","html_url":"https://github.com/jackowaya","followers_url":"https://api.github.com/users/jackowaya/followers","following_url":"https://api.github.com/users/jackowaya/following{/other_user}","gists_url":"https://api.github.com/users/jackowaya/gists{/gist_id}","starred_url":"https://api.github.com/users/jackowaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackowaya/subscriptions","organizations_url":"https://api.github.com/users/jackowaya/orgs","repos_url":"https://api.github.com/users/jackowaya/repos","events_url":"https://api.github.com/users/jackowaya/events{/privacy}","received_events_url":"https://api.github.com/users/jackowaya/received_events","type":"User","site_admin":false},"body":"Implemented a new NiFi processor that allows avro records to be converted from one Avro schema\r\nto another. This supports..\r\n* Flattening records using . notation like \"parent.id\"\r\n* Simple type conversions to String or base primitive types.","created_at":"2015-07-07T21:32:41Z","updated_at":"2015-07-08T17:14:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c2551b6c4225587a513f36a4452f0c7e70ac7920","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-nifi/pulls/70/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-nifi/pulls/70/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-nifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-nifi/issues/70/comments","statuses_url":"https://api.github.com/repos/apache/incubator-nifi/statuses/d50171381f853334bb670edb5581445fdfef0e46","head":{"label":"jackowaya:avroconvert","ref":"avroconvert","sha":"d50171381f853334bb670edb5581445fdfef0e46","user":{"login":"jackowaya","id":450988,"avatar_url":"https://avatars.githubusercontent.com/u/450988?v=3","gravatar_id":"","url":"https://api.github.com/users/jackowaya","html_url":"https://github.com/jackowaya","followers_url":"https://api.github.com/users/jackowaya/followers","following_url":"https://api.github.com/users/jackowaya/following{/other_user}","gists_url":"https://api.github.com/users/jackowaya/gists{/gist_id}","starred_url":"https://api.github.com/users/jackowaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackowaya/subscriptions","organizations_url":"https://api.github.com/users/jackowaya/orgs","repos_url":"https://api.github.com/users/jackowaya/repos","events_url":"https://api.github.com/users/jackowaya/events{/privacy}","received_events_url":"https://api.github.com/users/jackowaya/received_events","type":"User","site_admin":false},"repo":{"id":38706312,"name":"incubator-nifi","full_name":"jackowaya/incubator-nifi","owner":{"login":"jackowaya","id":450988,"avatar_url":"https://avatars.githubusercontent.com/u/450988?v=3","gravatar_id":"","url":"https://api.github.com/users/jackowaya","html_url":"https://github.com/jackowaya","followers_url":"https://api.github.com/users/jackowaya/followers","following_url":"https://api.github.com/users/jackowaya/following{/other_user}","gists_url":"https://api.github.com/users/jackowaya/gists{/gist_id}","starred_url":"https://api.github.com/users/jackowaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jackowaya/subscriptions","organizations_url":"https://api.github.com/users/jackowaya/orgs","repos_url":"https://api.github.com/users/jackowaya/repos","events_url":"https://api.github.com/users/jackowaya/events{/privacy}","received_events_url":"https://api.github.com/users/jackowaya/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jackowaya/incubator-nifi","description":"Mirror of Apache NiFi (Incubating)","fork":true,"url":"https://api.github.com/repos/jackowaya/incubator-nifi","forks_url":"https://api.github.com/repos/jackowaya/incubator-nifi/forks","keys_url":"https://api.github.com/repos/jackowaya/incubator-nifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jackowaya/incubator-nifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jackowaya/incubator-nifi/teams","hooks_url":"https://api.github.com/repos/jackowaya/incubator-nifi/hooks","issue_events_url":"https://api.github.com/repos/jackowaya/incubator-nifi/issues/events{/number}","events_url":"https://api.github.com/repos/jackowaya/incubator-nifi/events","assignees_url":"https://api.github.com/repos/jackowaya/incubator-nifi/assignees{/user}","branches_url":"https://api.github.com/repos/jackowaya/incubator-nifi/branches{/branch}","tags_url":"https://api.github.com/repos/jackowaya/incubator-nifi/tags","blobs_url":"https://api.github.com/repos/jackowaya/incubator-nifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jackowaya/incubator-nifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jackowaya/incubator-nifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/jackowaya/incubator-nifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jackowaya/incubator-nifi/statuses/{sha}","languages_url":"https://api.github.com/repos/jackowaya/incubator-nifi/languages","stargazers_url":"https://api.github.com/repos/jackowaya/incubator-nifi/stargazers","contributors_url":"https://api.github.com/repos/jackowaya/incubator-nifi/contributors","subscribers_url":"https://api.github.com/repos/jackowaya/incubator-nifi/subscribers","subscription_url":"https://api.github.com/repos/jackowaya/incubator-nifi/subscription","commits_url":"https://api.github.com/repos/jackowaya/incubator-nifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/jackowaya/incubator-nifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/jackowaya/incubator-nifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/jackowaya/incubator-nifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/jackowaya/incubator-nifi/contents/{+path}","compare_url":"https://api.github.com/repos/jackowaya/incubator-nifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jackowaya/incubator-nifi/merges","archive_url":"https://api.github.com/repos/jackowaya/incubator-nifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jackowaya/incubator-nifi/downloads","issues_url":"https://api.github.com/repos/jackowaya/incubator-nifi/issues{/number}","pulls_url":"https://api.github.com/repos/jackowaya/incubator-nifi/pulls{/number}","milestones_url":"https://api.github.com/repos/jackowaya/incubator-nifi/milestones{/number}","notifications_url":"https://api.github.com/repos/jackowaya/incubator-nifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jackowaya/incubator-nifi/labels{/name}","releases_url":"https://api.github.com/repos/jackowaya/incubator-nifi/releases{/id}","created_at":"2015-07-07T18:18:05Z","updated_at":"2015-07-07T18:18:13Z","pushed_at":"2015-07-07T21:31:55Z","git_url":"git://github.com/jackowaya/incubator-nifi.git","ssh_url":"git@github.com:jackowaya/incubator-nifi.git","clone_url":"https://github.com/jackowaya/incubator-nifi.git","svn_url":"https://github.com/jackowaya/incubator-nifi","homepage":null,"size":53237,"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":"develop"}},"base":{"label":"apache:develop","ref":"develop","sha":"9fa03b43245cfba27fe084ac46b44f39856dbcbb","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":27911088,"name":"incubator-nifi","full_name":"apache/incubator-nifi","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-nifi","description":"Mirror of Apache NiFi (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-nifi","forks_url":"https://api.github.com/repos/apache/incubator-nifi/forks","keys_url":"https://api.github.com/repos/apache/incubator-nifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-nifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-nifi/teams","hooks_url":"https://api.github.com/repos/apache/incubator-nifi/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-nifi/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-nifi/events","assignees_url":"https://api.github.com/repos/apache/incubator-nifi/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-nifi/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-nifi/tags","blobs_url":"https://api.github.com/repos/apache/incubator-nifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-nifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-nifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-nifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-nifi/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-nifi/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-nifi/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-nifi/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-nifi/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-nifi/subscription","commits_url":"https://api.github.com/repos/apache/incubator-nifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-nifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-nifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-nifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-nifi/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-nifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-nifi/merges","archive_url":"https://api.github.com/repos/apache/incubator-nifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-nifi/downloads","issues_url":"https://api.github.com/repos/apache/incubator-nifi/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-nifi/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-nifi/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-nifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-nifi/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-nifi/releases{/id}","created_at":"2014-12-12T08:00:05Z","updated_at":"2015-06-30T18:52:51Z","pushed_at":"2015-07-08T14:20:56Z","git_url":"git://github.com/apache/incubator-nifi.git","ssh_url":"git@github.com:apache/incubator-nifi.git","clone_url":"https://github.com/apache/incubator-nifi.git","svn_url":"https://github.com/apache/incubator-nifi","homepage":null,"size":53237,"stargazers_count":62,"watchers_count":62,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":60,"mirror_url":"git://git.apache.org/incubator-nifi.git","open_issues_count":6,"forks":60,"open_issues":6,"watchers":62,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-nifi/pulls/70"},"html":{"href":"https://github.com/apache/incubator-nifi/pull/70"},"issue":{"href":"https://api.github.com/repos/apache/incubator-nifi/issues/70"},"comments":{"href":"https://api.github.com/repos/apache/incubator-nifi/issues/70/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-nifi/pulls/70/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-nifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-nifi/pulls/70/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-nifi/statuses/d50171381f853334bb670edb5581445fdfef0e46"}}}}