{"action":"created","comment":{"url":"https://api.github.com/repos/apache/incubator-metron/pulls/comments/64777528","id":64777528,"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+\n+package org.apache.metron.common.field.transformation;\n+\n+import com.google.common.collect.Iterables;\n+import org.adrianwalker.multilinestring.Multiline;\n+import org.apache.hadoop.hbase.util.Bytes;\n+import org.apache.metron.common.configuration.FieldTransformer;\n+import org.apache.metron.common.configuration.SensorParserConfig;\n+import org.json.simple.JSONObject;\n+import org.junit.Assert;\n+import org.junit.Test;\n+\n+import java.util.HashMap;\n+\n+public class RemoveTransformationTest {\n+  /**\n+   {\n+    \"fieldTransformations\" : [\n+          {\n+            \"input\" : \"field1\"\n+          , \"transformation\" : \"REMOVE\"\n+          }\n+                      ]\n+   }\n+   */\n+  @Multiline\n+  public static String removeUnconditionalConfig;\n+\n+  @Test\n+  public void testUnconditionalRemove() throws Exception{\n+    SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeUnconditionalConfig));\n+    FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);\n+    JSONObject input = new JSONObject(new HashMap<String, Object>() {{\n+      put(\"field1\", \"foo\");\n+    }});\n+    handler.transformAndUpdate(input, new HashMap<>());\n+    Assert.assertFalse(input.containsKey(\"field1\"));\n+  }\n+\n+  /**\n+   {\n+    \"fieldTransformations\" : [\n+          {\n+            \"input\" : \"field1\"\n+          , \"transformation\" : \"REMOVE\"\n+          , \"config\" : {\n+              \"condition\" : \"exists(field2) and field2 == 'foo'\"\n+                       }\n+          }\n+                      ]\n+   }\n+   */\n+  @Multiline\n+  public static String removeConditionalConfig;\n+  @Test\n+  public void testConditionalRemove() throws Exception {\n+    SensorParserConfig c = SensorParserConfig.fromBytes(Bytes.toBytes(removeConditionalConfig));\n+    FieldTransformer handler = Iterables.getFirst(c.getFieldTransformations(), null);\n+    {\n+      JSONObject input = new JSONObject(new HashMap<String, Object>() {{\n+        put(\"field1\", \"foo\");\n+      }});\n+      handler.transformAndUpdate(input, new HashMap<>());\n+      Assert.assertTrue(input.containsKey(\"field1\"));\n+    }\n+    {\n+      JSONObject input = new JSONObject(new HashMap<String, Object>() {{\n+        put(\"field1\", \"foo\");\n+        put(\"field2\", \"bar\");\n+      }});\n+      handler.transformAndUpdate(input, new HashMap<>());\n+      Assert.assertTrue(input.containsKey(\"field1\"));","path":"metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/RemoveTransformationTest.java","position":89,"original_position":89,"commit_id":"50033949762e7a482649d27e64c9a61120b7f5df","original_commit_id":"50033949762e7a482649d27e64c9a61120b7f5df","user":{"login":"nickwallen","id":2475409,"avatar_url":"https://avatars.githubusercontent.com/u/2475409?v=3","gravatar_id":"","url":"https://api.github.com/users/nickwallen","html_url":"https://github.com/nickwallen","followers_url":"https://api.github.com/users/nickwallen/followers","following_url":"https://api.github.com/users/nickwallen/following{/other_user}","gists_url":"https://api.github.com/users/nickwallen/gists{/gist_id}","starred_url":"https://api.github.com/users/nickwallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nickwallen/subscriptions","organizations_url":"https://api.github.com/users/nickwallen/orgs","repos_url":"https://api.github.com/users/nickwallen/repos","events_url":"https://api.github.com/users/nickwallen/events{/privacy}","received_events_url":"https://api.github.com/users/nickwallen/received_events","type":"User","site_admin":false},"body":"I misunderstood the test.  Since field2 exists and its value is 'foo', then the code should not remove 'field1'.  And this is what you've asserted.  So looks good, but quick comments for those of us who are less bright would be awesome.","created_at":"2016-05-26T16:30:25Z","updated_at":"2016-05-26T16:30:25Z","html_url":"https://github.com/apache/incubator-metron/pull/136#discussion_r64777528","pull_request_url":"https://api.github.com/repos/apache/incubator-metron/pulls/136","_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-metron/pulls/comments/64777528"},"html":{"href":"https://github.com/apache/incubator-metron/pull/136#discussion_r64777528"},"pull_request":{"href":"https://api.github.com/repos/apache/incubator-metron/pulls/136"}}},"pull_request":{"url":"https://api.github.com/repos/apache/incubator-metron/pulls/136","id":71465202,"html_url":"https://github.com/apache/incubator-metron/pull/136","diff_url":"https://github.com/apache/incubator-metron/pull/136.diff","patch_url":"https://github.com/apache/incubator-metron/pull/136.patch","issue_url":"https://api.github.com/repos/apache/incubator-metron/issues/136","number":136,"state":"open","locked":false,"title":"METRON-186: Create a fieldMapping functionality which allows for parsed fields to be transformed","user":{"login":"cestella","id":540359,"avatar_url":"https://avatars.githubusercontent.com/u/540359?v=3","gravatar_id":"","url":"https://api.github.com/users/cestella","html_url":"https://github.com/cestella","followers_url":"https://api.github.com/users/cestella/followers","following_url":"https://api.github.com/users/cestella/following{/other_user}","gists_url":"https://api.github.com/users/cestella/gists{/gist_id}","starred_url":"https://api.github.com/users/cestella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cestella/subscriptions","organizations_url":"https://api.github.com/users/cestella/orgs","repos_url":"https://api.github.com/users/cestella/repos","events_url":"https://api.github.com/users/cestella/events{/privacy}","received_events_url":"https://api.github.com/users/cestella/received_events","type":"User","site_admin":false},"body":"Currently the parsers take care of transforming raw data to the parsed JSON representation. Allow for a layer to be placed at a sensor level to transform input fields from the parsed messages to create new fields. For instance, mapping IANA protocol numbers to a standardized textual representation (i.e. 6 maps to TCP).\r\n\r\nThis should be generalized, so that we can provide common functions and users can define the input fields and the output field to use.  This configuration should live with the sensor configuration in zookeeper.","created_at":"2016-05-25T21:21:06Z","updated_at":"2016-05-26T16:30:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe0e2aacc654cb1cc9ae8dac3b563afe41e4bbb2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/incubator-metron/pulls/136/commits","review_comments_url":"https://api.github.com/repos/apache/incubator-metron/pulls/136/comments","review_comment_url":"https://api.github.com/repos/apache/incubator-metron/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/incubator-metron/issues/136/comments","statuses_url":"https://api.github.com/repos/apache/incubator-metron/statuses/50033949762e7a482649d27e64c9a61120b7f5df","head":{"label":"cestella:transformers","ref":"transformers","sha":"50033949762e7a482649d27e64c9a61120b7f5df","user":{"login":"cestella","id":540359,"avatar_url":"https://avatars.githubusercontent.com/u/540359?v=3","gravatar_id":"","url":"https://api.github.com/users/cestella","html_url":"https://github.com/cestella","followers_url":"https://api.github.com/users/cestella/followers","following_url":"https://api.github.com/users/cestella/following{/other_user}","gists_url":"https://api.github.com/users/cestella/gists{/gist_id}","starred_url":"https://api.github.com/users/cestella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cestella/subscriptions","organizations_url":"https://api.github.com/users/cestella/orgs","repos_url":"https://api.github.com/users/cestella/repos","events_url":"https://api.github.com/users/cestella/events{/privacy}","received_events_url":"https://api.github.com/users/cestella/received_events","type":"User","site_admin":false},"repo":{"id":47701789,"name":"incubator-metron","full_name":"cestella/incubator-metron","owner":{"login":"cestella","id":540359,"avatar_url":"https://avatars.githubusercontent.com/u/540359?v=3","gravatar_id":"","url":"https://api.github.com/users/cestella","html_url":"https://github.com/cestella","followers_url":"https://api.github.com/users/cestella/followers","following_url":"https://api.github.com/users/cestella/following{/other_user}","gists_url":"https://api.github.com/users/cestella/gists{/gist_id}","starred_url":"https://api.github.com/users/cestella/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cestella/subscriptions","organizations_url":"https://api.github.com/users/cestella/orgs","repos_url":"https://api.github.com/users/cestella/repos","events_url":"https://api.github.com/users/cestella/events{/privacy}","received_events_url":"https://api.github.com/users/cestella/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cestella/incubator-metron","description":"Mirror of Apache Metron (Incubating)","fork":true,"url":"https://api.github.com/repos/cestella/incubator-metron","forks_url":"https://api.github.com/repos/cestella/incubator-metron/forks","keys_url":"https://api.github.com/repos/cestella/incubator-metron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cestella/incubator-metron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cestella/incubator-metron/teams","hooks_url":"https://api.github.com/repos/cestella/incubator-metron/hooks","issue_events_url":"https://api.github.com/repos/cestella/incubator-metron/issues/events{/number}","events_url":"https://api.github.com/repos/cestella/incubator-metron/events","assignees_url":"https://api.github.com/repos/cestella/incubator-metron/assignees{/user}","branches_url":"https://api.github.com/repos/cestella/incubator-metron/branches{/branch}","tags_url":"https://api.github.com/repos/cestella/incubator-metron/tags","blobs_url":"https://api.github.com/repos/cestella/incubator-metron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cestella/incubator-metron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cestella/incubator-metron/git/refs{/sha}","trees_url":"https://api.github.com/repos/cestella/incubator-metron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cestella/incubator-metron/statuses/{sha}","languages_url":"https://api.github.com/repos/cestella/incubator-metron/languages","stargazers_url":"https://api.github.com/repos/cestella/incubator-metron/stargazers","contributors_url":"https://api.github.com/repos/cestella/incubator-metron/contributors","subscribers_url":"https://api.github.com/repos/cestella/incubator-metron/subscribers","subscription_url":"https://api.github.com/repos/cestella/incubator-metron/subscription","commits_url":"https://api.github.com/repos/cestella/incubator-metron/commits{/sha}","git_commits_url":"https://api.github.com/repos/cestella/incubator-metron/git/commits{/sha}","comments_url":"https://api.github.com/repos/cestella/incubator-metron/comments{/number}","issue_comment_url":"https://api.github.com/repos/cestella/incubator-metron/issues/comments{/number}","contents_url":"https://api.github.com/repos/cestella/incubator-metron/contents/{+path}","compare_url":"https://api.github.com/repos/cestella/incubator-metron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cestella/incubator-metron/merges","archive_url":"https://api.github.com/repos/cestella/incubator-metron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cestella/incubator-metron/downloads","issues_url":"https://api.github.com/repos/cestella/incubator-metron/issues{/number}","pulls_url":"https://api.github.com/repos/cestella/incubator-metron/pulls{/number}","milestones_url":"https://api.github.com/repos/cestella/incubator-metron/milestones{/number}","notifications_url":"https://api.github.com/repos/cestella/incubator-metron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cestella/incubator-metron/labels{/name}","releases_url":"https://api.github.com/repos/cestella/incubator-metron/releases{/id}","deployments_url":"https://api.github.com/repos/cestella/incubator-metron/deployments","created_at":"2015-12-09T15:57:23Z","updated_at":"2016-01-27T14:23:10Z","pushed_at":"2016-05-26T16:20:23Z","git_url":"git://github.com/cestella/incubator-metron.git","ssh_url":"git@github.com:cestella/incubator-metron.git","clone_url":"https://github.com/cestella/incubator-metron.git","svn_url":"https://github.com/cestella/incubator-metron","homepage":null,"size":45275,"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":"f374daa05abd68a5a962be3da5a429b496778e8c","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":47607561,"name":"incubator-metron","full_name":"apache/incubator-metron","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-metron","description":"Mirror of Apache Metron (Incubating)","fork":false,"url":"https://api.github.com/repos/apache/incubator-metron","forks_url":"https://api.github.com/repos/apache/incubator-metron/forks","keys_url":"https://api.github.com/repos/apache/incubator-metron/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/incubator-metron/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/incubator-metron/teams","hooks_url":"https://api.github.com/repos/apache/incubator-metron/hooks","issue_events_url":"https://api.github.com/repos/apache/incubator-metron/issues/events{/number}","events_url":"https://api.github.com/repos/apache/incubator-metron/events","assignees_url":"https://api.github.com/repos/apache/incubator-metron/assignees{/user}","branches_url":"https://api.github.com/repos/apache/incubator-metron/branches{/branch}","tags_url":"https://api.github.com/repos/apache/incubator-metron/tags","blobs_url":"https://api.github.com/repos/apache/incubator-metron/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/incubator-metron/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/incubator-metron/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/incubator-metron/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/incubator-metron/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/incubator-metron/languages","stargazers_url":"https://api.github.com/repos/apache/incubator-metron/stargazers","contributors_url":"https://api.github.com/repos/apache/incubator-metron/contributors","subscribers_url":"https://api.github.com/repos/apache/incubator-metron/subscribers","subscription_url":"https://api.github.com/repos/apache/incubator-metron/subscription","commits_url":"https://api.github.com/repos/apache/incubator-metron/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/incubator-metron/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/incubator-metron/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/incubator-metron/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/incubator-metron/contents/{+path}","compare_url":"https://api.github.com/repos/apache/incubator-metron/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/incubator-metron/merges","archive_url":"https://api.github.com/repos/apache/incubator-metron/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/incubator-metron/downloads","issues_url":"https://api.github.com/repos/apache/incubator-metron/issues{/number}","pulls_url":"https://api.github.com/repos/apache/incubator-metron/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/incubator-metron/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/incubator-metron/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/incubator-metron/labels{/name}","releases_url":"https://api.github.com/repos/apache/incubator-metron/releases{/id}","deployments_url":"https://api.github.com/repos/apache/incubator-metron/deployments","created_at":"2015-12-08T08:00:05Z","updated_at":"2016-05-24T14:27:07Z","pushed_at":"2016-05-26T16:20:24Z","git_url":"git://github.com/apache/incubator-metron.git","ssh_url":"git@github.com:apache/incubator-metron.git","clone_url":"https://github.com/apache/incubator-metron.git","svn_url":"https://github.com/apache/incubator-metron","homepage":null,"size":45563,"stargazers_count":57,"watchers_count":57,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":67,"mirror_url":"git://git.apache.org/incubator-metron.git","open_issues_count":13,"forks":67,"open_issues":13,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/incubator-metron/pulls/136"},"html":{"href":"https://github.com/apache/incubator-metron/pull/136"},"issue":{"href":"https://api.github.com/repos/apache/incubator-metron/issues/136"},"comments":{"href":"https://api.github.com/repos/apache/incubator-metron/issues/136/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/incubator-metron/pulls/136/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/incubator-metron/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/incubator-metron/pulls/136/commits"},"statuses":{"href":"https://api.github.com/repos/apache/incubator-metron/statuses/50033949762e7a482649d27e64c9a61120b7f5df"}}}}
{"actor":{"display_login":"nickwallen"}}