You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metron.apache.org by 1havran <gi...@git.apache.org> on 2018/01/28 14:45:11 UTC

[GitHub] metron pull request #912: METRON-1431 Adding REGEX_REPLACE(input, regex, val...

GitHub user 1havran opened a pull request:

    https://github.com/apache/metron/pull/912

    METRON-1431 Adding REGEX_REPLACE(input, regex, value) to Stellar

    ## Contributor Comments
    Adding REGEXP_REPLACE(input, pattern, value) function to Stellar that will replace all occurrences of regex pattern within the input by provided value.
    ```
    [Stellar]>>> ?REGEXP_REPLACE
    REGEXP_REPLACE
    Description: Replace all occurences of the regex pattern within the string by value
    
    Arguments:
            string - The input string
            pattern - The regex pattern to be replaced. Special characters must be escaped (e.g. \\d)
            value - The value to replace the regex pattern
    
    Returns: The modified input string with replaced values
    
    [Stellar]>>> IPs:='1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4 5.5.5.5'
    1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4 5.5.5.5
    [Stellar]>>> REGEXP_REPLACE(IPs, '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}', 'x.x.x.x')
    x.x.x.x x.x.x.x x.x.x.x x.x.x.x x.x.x.x
    [Stellar]>>>
    ```
    
    ## Pull Request Checklist
    
    Thank you for submitting a contribution to Apache Metron.  
    Please refer to our [Development Guidelines](https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=61332235) for the complete guide to follow for contributions.  
    Please refer also to our [Build Verification Guidelines](https://cwiki.apache.org/confluence/display/METRON/Verifying+Builds?show-miniview) for complete smoke testing guides.  
    
    
    In order to streamline the review of the contribution we ask you follow these guidelines and ask you to double check the following:
    
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? If not one needs to be created at [Metron Jira](https://issues.apache.org/jira/browse/METRON/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel).
    - [x] Does your PR title start with METRON-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    
    ### For code changes:
    - [x] Have you included steps to reproduce the behavior or problem that is being changed or addressed?
    - [x] Have you included steps or a guide to how the change may be verified and tested manually?
    - [x] Have you ensured that the full suite of tests and checks have been executed in the root metron folder via:
      ```
      mvn -q clean integration-test install && dev-utilities/build-utils/verify_licenses.sh 
      ```
    
    - [x] Have you written or updated unit tests and or integration tests to verify your changes?
    - [x] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
    - [x] Have you verified the basic functionality of the build by building and running locally with Vagrant full-dev environment or the equivalent?
    
    ### For documentation related changes:
    - [x] Have you ensured that format looks appropriate for the output in which it is rendered by building and verifying the site-book? If not then run the following commands and the verify changes via `site-book/target/site/index.html`:
    
      ```
      cd site-book
      mvn site
      ```
    
    #### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.
    It is also recommended that [travis-ci](https://travis-ci.org) is set up for your personal repository such that your branches are built there before submitting a pull request.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/1havran/metron metron-1431

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/metron/pull/912.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #912
    
----
commit f558c8277dff908965bd643f191af5fa39991c4a
Author: 1havran <ha...@...>
Date:   2018-01-28T14:08:27Z

    adding REGEX_REPLACE(input, regex, value)

----


---

[GitHub] metron pull request #912: METRON-1431 Adding REGEX_REPLACE(input, regex, val...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/metron/pull/912


---

[GitHub] metron issue #912: METRON-1431 Adding REGEX_REPLACE(input, regex, value) to ...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/912
  
    +1 by inspection.  Thank you for the contribution



---

[GitHub] metron pull request #912: METRON-1431 Adding REGEX_REPLACE(input, regex, val...

Posted by 1havran <gi...@git.apache.org>.
Github user 1havran commented on a diff in the pull request:

    https://github.com/apache/metron/pull/912#discussion_r164570355
  
    --- Diff: metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RegExFunctionsTest.java ---
    @@ -68,4 +68,19 @@ public void testRegExGroupVal() throws Exception {
           Assert.assertTrue("Did not fail on wrong number of parameters",false);
         }
       }
    +
    +  @Test
    +  public void testRegExReplace() throws Exception {
    +    final Map<String, String> variableMap = new HashMap<String, String>() {{
    +      put("numbers", "12345");
    +      put("numberPattern", "\\d(\\d)(\\d).*");
    +      put("letters", "abcde");
    +      put("empty", "");
    +    }};
    +
    --- End diff --
    
    Indeed, more tests included.


---

[GitHub] metron issue #912: METRON-1431 Adding REGEX_REPLACE(input, regex, value) to ...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on the issue:

    https://github.com/apache/metron/pull/912
  
    please remember to take care of your jira


---

[GitHub] metron pull request #912: METRON-1431 Adding REGEX_REPLACE(input, regex, val...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/912#discussion_r164303375
  
    --- Diff: metron-stellar/stellar-common/src/test/java/org/apache/metron/stellar/dsl/functions/RegExFunctionsTest.java ---
    @@ -68,4 +68,19 @@ public void testRegExGroupVal() throws Exception {
           Assert.assertTrue("Did not fail on wrong number of parameters",false);
         }
       }
    +
    +  @Test
    +  public void testRegExReplace() throws Exception {
    +    final Map<String, String> variableMap = new HashMap<String, String>() {{
    +      put("numbers", "12345");
    +      put("numberPattern", "\\d(\\d)(\\d).*");
    +      put("letters", "abcde");
    +      put("empty", "");
    +    }};
    +
    --- End diff --
    
    Can you add tests for passing in empty or null strings?


---

[GitHub] metron pull request #912: METRON-1431 Adding REGEX_REPLACE(input, regex, val...

Posted by 1havran <gi...@git.apache.org>.
Github user 1havran commented on a diff in the pull request:

    https://github.com/apache/metron/pull/912#discussion_r164570247
  
    --- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RegExFunctions.java ---
    @@ -100,4 +100,39 @@ public Object apply(List<Object> list) {
           return matcher.group(groupNumber);
         }
       }
    +
    +  @Stellar(name = "REGEXP_REPLACE",
    +      description = "Replace all occurences of the regex pattern within the string by value",
    +      params = {
    +          "string - The input string",
    +          "pattern - The regex pattern to be replaced. Special characters must be escaped (e.g. \\\\d)",
    +          "value - The value to replace the regex pattern"
    +      },
    +      returns = "The modified input string with replaced values")
    +  public static class RegexpReplace extends BaseStellarFunction {
    +
    +    @Override
    +    public Object apply(List<Object> list) {
    +      if (list.size() != 3) {
    +        throw new IllegalStateException(
    +            "REGEXP_REPLACE expects three args: [string, pattern, value]"
    +                + " where pattern is a regexp pattern");
    +      }
    +      String str = (String) list.get(0);
    +      String stringPattern = (String) list.get(1);
    +      String value = (String) list.get(2);
    +
    --- End diff --
    
    Thanks for a hint, it is fixed now.


---

[GitHub] metron pull request #912: METRON-1431 Adding REGEX_REPLACE(input, regex, val...

Posted by ottobackwards <gi...@git.apache.org>.
Github user ottobackwards commented on a diff in the pull request:

    https://github.com/apache/metron/pull/912#discussion_r164303393
  
    --- Diff: metron-stellar/stellar-common/src/main/java/org/apache/metron/stellar/dsl/functions/RegExFunctions.java ---
    @@ -100,4 +100,39 @@ public Object apply(List<Object> list) {
           return matcher.group(groupNumber);
         }
       }
    +
    +  @Stellar(name = "REGEXP_REPLACE",
    +      description = "Replace all occurences of the regex pattern within the string by value",
    +      params = {
    +          "string - The input string",
    +          "pattern - The regex pattern to be replaced. Special characters must be escaped (e.g. \\\\d)",
    +          "value - The value to replace the regex pattern"
    +      },
    +      returns = "The modified input string with replaced values")
    +  public static class RegexpReplace extends BaseStellarFunction {
    +
    +    @Override
    +    public Object apply(List<Object> list) {
    +      if (list.size() != 3) {
    +        throw new IllegalStateException(
    +            "REGEXP_REPLACE expects three args: [string, pattern, value]"
    +                + " where pattern is a regexp pattern");
    +      }
    +      String str = (String) list.get(0);
    +      String stringPattern = (String) list.get(1);
    +      String value = (String) list.get(2);
    +
    --- End diff --
    
    I think you want to check for null or empty
    
    StringUtils.isEmpty(str)


---