[ 
https://issues.apache.org/jira/browse/METRON-186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15302338#comment-15302338
 ] 

ASF GitHub Bot commented on METRON-186:
---------------------------------------

Github user nickwallen commented on a diff in the pull request:

    https://github.com/apache/incubator-metron/pull/136#discussion_r64776627
  
    --- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/RemoveTransformationTest.java
 ---
    @@ -0,0 +1,100 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.metron.common.field.transformation;
    +
    +import com.google.common.collect.Iterables;
    +import org.adrianwalker.multilinestring.Multiline;
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.metron.common.configuration.FieldTransformer;
    +import org.apache.metron.common.configuration.SensorParserConfig;
    +import org.json.simple.JSONObject;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.util.HashMap;
    +
    +public class RemoveTransformationTest {
    +  /**
    +   {
    +    "fieldTransformations" : [
    +          {
    +            "input" : "field1"
    +          , "transformation" : "REMOVE"
    +          }
    +                      ]
    +   }
    +   */
    +  @Multiline
    +  public static String removeUnconditionalConfig;
    +
    +  @Test
    +  public void testUnconditionalRemove() throws Exception{
    +    SensorParserConfig c = 
SensorParserConfig.fromBytes(Bytes.toBytes(removeUnconditionalConfig));
    +    FieldTransformer handler = 
Iterables.getFirst(c.getFieldTransformations(), null);
    +    JSONObject input = new JSONObject(new HashMap<String, Object>() {{
    +      put("field1", "foo");
    +    }});
    +    handler.transformAndUpdate(input, new HashMap<>());
    +    Assert.assertFalse(input.containsKey("field1"));
    +  }
    +
    +  /**
    +   {
    +    "fieldTransformations" : [
    +          {
    +            "input" : "field1"
    +          , "transformation" : "REMOVE"
    +          , "config" : {
    +              "condition" : "exists(field2) and field2 == 'foo'"
    +                       }
    +          }
    +                      ]
    +   }
    +   */
    +  @Multiline
    +  public static String removeConditionalConfig;
    +  @Test
    +  public void testConditionalRemove() throws Exception {
    +    SensorParserConfig c = 
SensorParserConfig.fromBytes(Bytes.toBytes(removeConditionalConfig));
    +    FieldTransformer handler = 
Iterables.getFirst(c.getFieldTransformations(), null);
    +    {
    +      JSONObject input = new JSONObject(new HashMap<String, Object>() {{
    +        put("field1", "foo");
    +      }});
    +      handler.transformAndUpdate(input, new HashMap<>());
    +      Assert.assertTrue(input.containsKey("field1"));
    +    }
    +    {
    +      JSONObject input = new JSONObject(new HashMap<String, Object>() {{
    +        put("field1", "foo");
    +        put("field2", "bar");
    +      }});
    +      handler.transformAndUpdate(input, new HashMap<>());
    +      Assert.assertTrue(input.containsKey("field1"));
    +    }
    +    {
    +      JSONObject input = new JSONObject(new HashMap<String, Object>() {{
    +        put("field1", "bar");
    +        put("field2", "foo");
    +      }});
    +      handler.transformAndUpdate(input, new HashMap<>());
    +      Assert.assertEquals("bar", input.get("field1"));
    --- End diff --
    
    Does this test ensure that 'field2' has been removed?


> Create a fieldMapping functionality which allows for parsed fields to be 
> transformed
> ------------------------------------------------------------------------------------
>
>                 Key: METRON-186
>                 URL: https://issues.apache.org/jira/browse/METRON-186
>             Project: Metron
>          Issue Type: Improvement
>            Reporter: Casey Stella
>            Assignee: Casey Stella
>
> 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).



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to