You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by MikeThomsen <gi...@git.apache.org> on 2018/03/17 01:53:30 UTC

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

GitHub user MikeThomsen opened a pull request:

    https://github.com/apache/nifi/pull/2560

    NIFI-4989 Made PutMongo able to use nested lookup keys, a query param…

    … and multiple lookup keys.
    
    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [ ] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [ ] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [ ] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [ ] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [ ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [ ] Have you written or updated unit tests to verify your changes?
    - [ ] 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)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### 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.


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

    $ git pull https://github.com/MikeThomsen/nifi NIFI-4989

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

    https://github.com/apache/nifi/pull/2560.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 #2560
    
----
commit 380e342643885b8919599a1e8d329dfbb89600a6
Author: Mike Thomsen <mi...@...>
Date:   2018-03-17T01:51:19Z

    NIFI-4989 Made PutMongo able to use nested lookup keys, a query param and multiple lookup keys.

----


---

[GitHub] nifi issue #2560: NIFI-4989 Made PutMongo able to use nested lookup keys, a ...

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

    https://github.com/apache/nifi/pull/2560
  
    Done, merged to master, thanks @MikeThomsen @zenfenan 


---

[GitHub] nifi issue #2560: NIFI-4989 Made PutMongo able to use nested lookup keys, a ...

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

    https://github.com/apache/nifi/pull/2560
  
    I think that works. I'll try to find some time tonight to get that done.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175844689
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    Understood. So this is critical when doing replace i.e. the mode is set to `UPDATE_WITH_DOC`. Correct?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175286408
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -137,6 +151,31 @@
             return propertyDescriptors;
         }
     
    +    @Override
    +    protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    +        List<ValidationResult> problems = new ArrayList<>();
    +
    +        final boolean queryKey = validationContext.getProperty(UPDATE_QUERY_KEY).isSet()
    +                && !StringUtils.isBlank(validationContext.getProperty(UPDATE_QUERY_KEY).getValue());
    --- End diff --
    
    I just remembered why I did this. When you call `removeProperty` to unset the property, the `getProperty` call here will return the default value. So maybe I need to remove the default value. What do you think? Is this a problem with the test helpers or my understanding of how properties should work?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175284988
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -86,19 +91,27 @@
             .name("Update Query Key")
             .description("Key name used to build the update query criteria; this property is valid only when using update mode, "
                     + "otherwise it is ignored")
    -        .required(true)
    -        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +        .required(false)
    +        .addValidator(Validator.VALID)
    --- End diff --
    
    Since required is set to false, you can still use the original validor: it'll be used only if a value is set. No? Unless you really want someone to be able to set an empty string as a possible value.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560


---

[GitHub] nifi issue #2560: NIFI-4989 Made PutMongo able to use nested lookup keys, a ...

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

    https://github.com/apache/nifi/pull/2560
  
    @pvillard31 Can you merge your change so we can close this out?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175286257
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java ---
    @@ -96,6 +99,125 @@ public void testValidators() {
             Assert.assertEquals(0, results.size());
         }
     
    +    @Test
    +    public void testQueryAndUpdateKey() {
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "_id");
    +        runner.setProperty(PutMongo.UPDATE_QUERY, "{}");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testNoQueryAndNoUpdateKey() {
    +        runner.removeProperty(PutMongo.UPDATE_QUERY);
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testBlankUpdateKey() {
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "  ");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testUpdateQuery() {
    +        Document document = new Document()
    +            .append("name", "John Smith")
    +            .append("department", "Engineering");
    +        collection.insertOne(document);
    +        String updateBody = "{\n" +
    +            "\t\"$set\": {\n" +
    +            "\t\t\"email\": \"john.smith@test.com\",\n" +
    +            "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
    +            "\t},\n" +
    +            "\t\"$inc\": {\n" +
    +            "\t\t\"writes\": 1\n" +
    +            "\t}\n" +
    +            "}";
    +        Map<String, String> attr = new HashMap<>();
    +        attr.put("mongo.update.query", document.toJson());
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
    +        runner.setProperty(PutMongo.UPDATE_MODE, PutMongo.UPDATE_WITH_OPERATORS);
    +        runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
    +        runner.setProperty(PutMongo.UPDATE_QUERY, "${mongo.update.query}");
    +        runner.setValidateExpressionUsage(true);
    +        runner.enqueue(updateBody, attr);
    +        updateTests(document);
    +    }
    +
    +    @Test
    +    public void testUpdateBySimpleKey() {
    +        Document document = new Document()
    +            .append("name", "John Smith")
    +            .append("department", "Engineering");
    +        collection.insertOne(document);
    +        String updateBody = "{\n" +
    +            "\t\"name\": \"John Smith\",\n" +
    +            "\t\"$set\": {\n" +
    +            "\t\t\"email\": \"john.smith@test.com\",\n" +
    +            "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
    +            "\t},\n" +
    +            "\t\"$inc\": {\n" +
    +            "\t\t\"writes\": 1\n" +
    +            "\t}\n" +
    +            "}";
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "name");
    +        runner.setProperty(PutMongo.UPDATE_MODE, PutMongo.UPDATE_WITH_OPERATORS);
    +        runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
    +        runner.setValidateExpressionUsage(true);
    +        runner.enqueue(updateBody);
    +        updateTests(document);
    +    }
    +
    +    @Test
    --- End diff --
    
    Yeah. I'm adding 2 at the moment. One for update by keys and one for query.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175838320
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    Also, again, complex key names simply wouldn't have any value to over 99% of Mongo users. As I said, I'm sure there's a few random users that want to chuck something like this in Mongo:
    
    ```
    {
        "user.name": "john.smith",
        "user.contact.email": "john.smith@test.com"
    }
    ```
    
    Accommodating that would be detrimental to providing a consistent tool for the vast majority of Mongo users. 


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175285785
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -86,19 +91,27 @@
             .name("Update Query Key")
             .description("Key name used to build the update query criteria; this property is valid only when using update mode, "
                     + "otherwise it is ignored")
    -        .required(true)
    -        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +        .required(false)
    +        .addValidator(Validator.VALID)
    --- End diff --
    
    Wasn't sure if that's the case.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175278421
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/test/java/org/apache/nifi/processors/mongodb/PutMongoIT.java ---
    @@ -96,6 +99,125 @@ public void testValidators() {
             Assert.assertEquals(0, results.size());
         }
     
    +    @Test
    +    public void testQueryAndUpdateKey() {
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "_id");
    +        runner.setProperty(PutMongo.UPDATE_QUERY, "{}");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testNoQueryAndNoUpdateKey() {
    +        runner.removeProperty(PutMongo.UPDATE_QUERY);
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testBlankUpdateKey() {
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "  ");
    +        runner.assertNotValid();
    +    }
    +
    +    @Test
    +    public void testUpdateQuery() {
    +        Document document = new Document()
    +            .append("name", "John Smith")
    +            .append("department", "Engineering");
    +        collection.insertOne(document);
    +        String updateBody = "{\n" +
    +            "\t\"$set\": {\n" +
    +            "\t\t\"email\": \"john.smith@test.com\",\n" +
    +            "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
    +            "\t},\n" +
    +            "\t\"$inc\": {\n" +
    +            "\t\t\"writes\": 1\n" +
    +            "\t}\n" +
    +            "}";
    +        Map<String, String> attr = new HashMap<>();
    +        attr.put("mongo.update.query", document.toJson());
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "");
    +        runner.setProperty(PutMongo.UPDATE_MODE, PutMongo.UPDATE_WITH_OPERATORS);
    +        runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
    +        runner.setProperty(PutMongo.UPDATE_QUERY, "${mongo.update.query}");
    +        runner.setValidateExpressionUsage(true);
    +        runner.enqueue(updateBody, attr);
    +        updateTests(document);
    +    }
    +
    +    @Test
    +    public void testUpdateBySimpleKey() {
    +        Document document = new Document()
    +            .append("name", "John Smith")
    +            .append("department", "Engineering");
    +        collection.insertOne(document);
    +        String updateBody = "{\n" +
    +            "\t\"name\": \"John Smith\",\n" +
    +            "\t\"$set\": {\n" +
    +            "\t\t\"email\": \"john.smith@test.com\",\n" +
    +            "\t\t\"grade\": \"Sr. Principle Eng.\"\n" +
    +            "\t},\n" +
    +            "\t\"$inc\": {\n" +
    +            "\t\t\"writes\": 1\n" +
    +            "\t}\n" +
    +            "}";
    +        runner.setProperty(PutMongo.UPDATE_QUERY_KEY, "name");
    +        runner.setProperty(PutMongo.UPDATE_MODE, PutMongo.UPDATE_WITH_OPERATORS);
    +        runner.setProperty(PutMongo.MODE, PutMongo.MODE_UPDATE);
    +        runner.setValidateExpressionUsage(true);
    +        runner.enqueue(updateBody);
    +        updateTests(document);
    +    }
    +
    +    @Test
    --- End diff --
    
    If possible, would love to see a similar test but with `PutMongo.UPDATE_WITH_DOC`


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175286234
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -169,14 +208,16 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
                     // update
                     final boolean upsert = context.getProperty(UPSERT).asBoolean();
                     final String updateKey = context.getProperty(UPDATE_QUERY_KEY).getValue();
    +                final String updateQuery = context.getProperty(UPDATE_QUERY).evaluateAttributeExpressions(flowFile).getValue();
    +                final Document query;
     
    -                Object keyVal = ((Map)doc).get(updateKey);
    -                if (updateKey.equals("_id") && ObjectId.isValid(((String)keyVal))) {
    -                    keyVal = new ObjectId((String) keyVal);
    +                if (!StringUtils.isBlank(updateKey)) {
    +                    query = parseUpdateKey(updateKey, (Map)doc);
    +                    removeUpdateKeys(updateKey, (Map)doc);
    +                } else {
    +                    query = Document.parse(updateQuery);
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175285159
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -137,6 +151,31 @@
             return propertyDescriptors;
         }
     
    +    @Override
    +    protected Collection<ValidationResult> customValidate(final ValidationContext validationContext) {
    +        List<ValidationResult> problems = new ArrayList<>();
    +
    +        final boolean queryKey = validationContext.getProperty(UPDATE_QUERY_KEY).isSet()
    +                && !StringUtils.isBlank(validationContext.getProperty(UPDATE_QUERY_KEY).getValue());
    --- End diff --
    
    You don't need to check that if my previous comment is valid (since, if a value is set, the validator will check that's the value is not empty)


---

[GitHub] nifi issue #2560: NIFI-4989 Made PutMongo able to use nested lookup keys, a ...

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

    https://github.com/apache/nifi/pull/2560
  
    @MikeThomsen - can you have a look at this commit: https://github.com/pvillard31/nifi/commit/5a67aa152bf2844de6a9192bfb75a073e80a595b
    
    I reworked a bit the tests to avoid "removing" a property while executing the tests. Basically, instead of having a shared instance of the TestRunner for all the test suite, I initialize one eache time (to be sure there is no conflict between the tests and to avoid issues in cases tests are not executed in the same order each time). Regarding your comment about the validation failing, it's because we're providing a default value "_id". Because of that the property will always return true to isSet(). Since we're adding a new property and the user needs to use one of the two, I suggest removing the default value: it does not break anything, and it "forces" the user to understand the choice the user is doing. Does that make sense?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175296639
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    For this input:
    
    ```
    {
        "name": "John Smith",
        "department": "Engineering"
    }
    ```
    
    It makes no sense to remove `name` if we're doing a full document update using the `name key.
    
    Now consider this complex document:
    
    ```
    {
        "name": "John Smith",
        "department": "Engineering",
        "contacts": {
             "email": "john.smith@test.com"
         }
    }
    ```
    
    To search on `email`, we have to submit this payload with the lookup key being `contacts.email`:
    
    ```
    {
        "contacts.email": "john.smith@test.com",
        "name": "John Smith",
        "department": "Engineering",
        "contacts": {
             "email": "john.smith@test.com"
         }
    }
    ```
    
    Mongo cannot do a lookup using this: `{ "contacts": { "email": "john.smith@test.com" }}`
    
    So if we don't remove the complex lookup key, we are leaving extraneous information in the document that almost certainly has no value to the user.
    
    Now maybe we'll get an angry ticket complaining that they can't do periods in the key names, but I've never seen normal use cases where developers do that. The whole idea of creating complex key names for real data using periods and such flies in the face of how JSON is supposed to work.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175278403
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -169,14 +208,16 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
                     // update
                     final boolean upsert = context.getProperty(UPSERT).asBoolean();
                     final String updateKey = context.getProperty(UPDATE_QUERY_KEY).getValue();
    +                final String updateQuery = context.getProperty(UPDATE_QUERY).evaluateAttributeExpressions(flowFile).getValue();
    +                final Document query;
     
    -                Object keyVal = ((Map)doc).get(updateKey);
    -                if (updateKey.equals("_id") && ObjectId.isValid(((String)keyVal))) {
    -                    keyVal = new ObjectId((String) keyVal);
    +                if (!StringUtils.isBlank(updateKey)) {
    +                    query = parseUpdateKey(updateKey, (Map)doc);
    +                    removeUpdateKeys(updateKey, (Map)doc);
    +                } else {
    +                    query = Document.parse(updateQuery);
    --- End diff --
    
    Shall we change it to `filterQuery` ? Purely a cosmetic change, feel free to ignore it but I think it follows a better naming convention since it's actually a *filter* query based on which the update is done.


---

[GitHub] nifi issue #2560: NIFI-4989 Made PutMongo able to use nested lookup keys, a ...

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

    https://github.com/apache/nifi/pull/2560
  
    @pvillard31 Thoughts on merging this?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175820396
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    No.. what I meant was, regardless of whether we have a complex key or simple key, we don't need them to exist in the parsed filter query, right? So why don't we simply remove this `if (part.contains("."))` check, basically meaning, remove the key from the `doc`. No?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175836334
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    > we don't need them to exist in the parsed filter query, right?
    
    We do when replacing one document with another. Say you have a user account document, and the update key is `username`. If the user is doing full document replacement, and we remove the update key, the `username` field is going to be removed from the document that is used in the substitution. So then the poor end users will be searching through an accounts collection looking for documents with no usernames.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175850266
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    Yes. The only time it wouldn't apply is if a user wanted to remove a field like they misnamed the `username` field as `yusername`. They can fix that with:
    
    ```
    {
        "yusername": "....",
        "$set": {
             "username": ".....",
         },
         "$unset": {
             "yusername": 1
         }
    }
    ```


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175286235
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -86,19 +91,27 @@
             .name("Update Query Key")
             .description("Key name used to build the update query criteria; this property is valid only when using update mode, "
                     + "otherwise it is ignored")
    -        .required(true)
    -        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +        .required(false)
    +        .addValidator(Validator.VALID)
             .defaultValue("_id")
             .build();
    +    static final PropertyDescriptor UPDATE_QUERY = new PropertyDescriptor.Builder()
    +        .name("putmongo-update-query")
    --- End diff --
    
    Done.


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175278309
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -86,19 +91,27 @@
             .name("Update Query Key")
             .description("Key name used to build the update query criteria; this property is valid only when using update mode, "
                     + "otherwise it is ignored")
    -        .required(true)
    -        .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
    +        .required(false)
    +        .addValidator(Validator.VALID)
             .defaultValue("_id")
             .build();
    +    static final PropertyDescriptor UPDATE_QUERY = new PropertyDescriptor.Builder()
    +        .name("putmongo-update-query")
    --- End diff --
    
    How about adding `description` here?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175289508
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    Forgot to raise this earlier. Why are we doing a check if it contains a `.` ? It will work only for complex keys and simple key will be ignored i.e. not removed, right?


---

[GitHub] nifi pull request #2560: NIFI-4989 Made PutMongo able to use nested lookup k...

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

    https://github.com/apache/nifi/pull/2560#discussion_r175850614
  
    --- Diff: nifi-nar-bundles/nifi-mongodb-bundle/nifi-mongodb-processors/src/main/java/org/apache/nifi/processors/mongodb/PutMongo.java ---
    @@ -196,6 +237,33 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
             }
         }
     
    +    private void removeUpdateKeys(String updateKeyParam, Map doc) {
    +        String[] parts = updateKeyParam.split(",[\\s]*");
    +        for (String part : parts) {
    +            if (part.contains(".")) {
    --- End diff --
    
    TBH, the sanest way to handle such mistakes would be to stop ingestion and run some JavaScript code to update the database properly.


---