You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by markap14 <gi...@git.apache.org> on 2017/09/12 14:02:45 UTC

[GitHub] nifi pull request #2147: NIFI-4377: Added a fieldName() function to RecordPa...

GitHub user markap14 opened a pull request:

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

    NIFI-4377: Added a fieldName() function to RecordPath and addressed a…

    …n issue that caused //* to not work
    
    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/markap14/nifi NIFI-4377

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

    https://github.com/apache/nifi/pull/2147.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 #2147
    
----
commit 658574a92850ea523f6a2b09ce9ba15fe321d38a
Author: Mark Payne <ma...@hotmail.com>
Date:   2017-09-12T14:02:16Z

    NIFI-4377: Added a fieldName() function to RecordPath and addressed an issue that caused //* to not work

----


---

[GitHub] nifi issue #2147: NIFI-4377: Added a fieldName() function to RecordPath and ...

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

    https://github.com/apache/nifi/pull/2147
  
    @pvillard31 I pushed a new commit to update the Record Path Guide. I also added to the unit tests for the fieldName() function


---

[GitHub] nifi issue #2147: NIFI-4377: Added a fieldName() function to RecordPath and ...

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

    https://github.com/apache/nifi/pull/2147
  
    reviewing


---

[GitHub] nifi pull request #2147: NIFI-4377: Added a fieldName() function to RecordPa...

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

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


---

[GitHub] nifi pull request #2147: NIFI-4377: Added a fieldName() function to RecordPa...

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

    https://github.com/apache/nifi/pull/2147#discussion_r138618390
  
    --- Diff: nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/WildcardDescendantPath.java ---
    @@ -0,0 +1,74 @@
    +/*
    + * 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.nifi.record.path.paths;
    +
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.stream.Stream;
    +
    +import org.apache.nifi.record.path.FieldValue;
    +import org.apache.nifi.record.path.RecordPathEvaluationContext;
    +import org.apache.nifi.record.path.StandardFieldValue;
    +import org.apache.nifi.record.path.util.Filters;
    +import org.apache.nifi.serialization.record.Record;
    +import org.apache.nifi.serialization.record.RecordField;
    +
    +public class WildcardDescendantPath extends RecordPathSegment {
    +
    +    WildcardDescendantPath(final RecordPathSegment parent, final boolean absolute) {
    +        super("/*", parent, absolute);
    +    }
    +
    +    @Override
    +    public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
    +        final Stream<FieldValue> parentResult = getParentPath().evaluate(context);
    +
    +        return parentResult
    +            .flatMap(recordFieldVal -> findDescendants(recordFieldVal).stream());
    +    }
    +
    +    private List<FieldValue> findDescendants(final FieldValue fieldValue) {
    +        if (fieldValue == null || fieldValue.getValue() == null) {
    +            return Collections.emptyList();
    +        }
    +        if (!Filters.isRecord(fieldValue)) {
    +            return Collections.emptyList();
    +        }
    +
    +        final Record record = (Record) fieldValue.getValue();
    --- End diff --
    
    Actually I think this is addressed already online 47:
    ```
    if (fieldValue == null || fieldValue.getValue() == null) {
        return Collections.emptyList();
    }
    ```


---

[GitHub] nifi pull request #2147: NIFI-4377: Added a fieldName() function to RecordPa...

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

    https://github.com/apache/nifi/pull/2147#discussion_r138449953
  
    --- Diff: nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/FieldName.java ---
    @@ -0,0 +1,42 @@
    +/*
    + * 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.nifi.record.path.functions;
    +
    +import java.util.stream.Stream;
    +
    +import org.apache.nifi.record.path.FieldValue;
    +import org.apache.nifi.record.path.RecordPathEvaluationContext;
    +import org.apache.nifi.record.path.StandardFieldValue;
    +import org.apache.nifi.record.path.paths.RecordPathSegment;
    +
    +public class FieldName extends RecordPathSegment {
    +    private final RecordPathSegment recordPath;
    +
    +    public FieldName(final RecordPathSegment recordPath, final boolean absolute) {
    +        super("fieldName", null, absolute);
    --- End diff --
    
    Should it be added to the documentation (Record Path Guide) with some examples?


---

[GitHub] nifi pull request #2147: NIFI-4377: Added a fieldName() function to RecordPa...

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

    https://github.com/apache/nifi/pull/2147#discussion_r138817250
  
    --- Diff: nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/WildcardDescendantPath.java ---
    @@ -0,0 +1,74 @@
    +/*
    + * 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.nifi.record.path.paths;
    +
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.stream.Stream;
    +
    +import org.apache.nifi.record.path.FieldValue;
    +import org.apache.nifi.record.path.RecordPathEvaluationContext;
    +import org.apache.nifi.record.path.StandardFieldValue;
    +import org.apache.nifi.record.path.util.Filters;
    +import org.apache.nifi.serialization.record.Record;
    +import org.apache.nifi.serialization.record.RecordField;
    +
    +public class WildcardDescendantPath extends RecordPathSegment {
    +
    +    WildcardDescendantPath(final RecordPathSegment parent, final boolean absolute) {
    +        super("/*", parent, absolute);
    +    }
    +
    +    @Override
    +    public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
    +        final Stream<FieldValue> parentResult = getParentPath().evaluate(context);
    +
    +        return parentResult
    +            .flatMap(recordFieldVal -> findDescendants(recordFieldVal).stream());
    +    }
    +
    +    private List<FieldValue> findDescendants(final FieldValue fieldValue) {
    +        if (fieldValue == null || fieldValue.getValue() == null) {
    +            return Collections.emptyList();
    +        }
    +        if (!Filters.isRecord(fieldValue)) {
    +            return Collections.emptyList();
    +        }
    +
    +        final Record record = (Record) fieldValue.getValue();
    --- End diff --
    
    Right!


---

[GitHub] nifi issue #2147: NIFI-4377: Added a fieldName() function to RecordPath and ...

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

    https://github.com/apache/nifi/pull/2147
  
    @pvillard31 both good catches. Will update & push a new commit. Thanks!


---

[GitHub] nifi pull request #2147: NIFI-4377: Added a fieldName() function to RecordPa...

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

    https://github.com/apache/nifi/pull/2147#discussion_r138450379
  
    --- Diff: nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/WildcardDescendantPath.java ---
    @@ -0,0 +1,74 @@
    +/*
    + * 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.nifi.record.path.paths;
    +
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.List;
    +import java.util.stream.Stream;
    +
    +import org.apache.nifi.record.path.FieldValue;
    +import org.apache.nifi.record.path.RecordPathEvaluationContext;
    +import org.apache.nifi.record.path.StandardFieldValue;
    +import org.apache.nifi.record.path.util.Filters;
    +import org.apache.nifi.serialization.record.Record;
    +import org.apache.nifi.serialization.record.RecordField;
    +
    +public class WildcardDescendantPath extends RecordPathSegment {
    +
    +    WildcardDescendantPath(final RecordPathSegment parent, final boolean absolute) {
    +        super("/*", parent, absolute);
    +    }
    +
    +    @Override
    +    public Stream<FieldValue> evaluate(final RecordPathEvaluationContext context) {
    +        final Stream<FieldValue> parentResult = getParentPath().evaluate(context);
    +
    +        return parentResult
    +            .flatMap(recordFieldVal -> findDescendants(recordFieldVal).stream());
    +    }
    +
    +    private List<FieldValue> findDescendants(final FieldValue fieldValue) {
    +        if (fieldValue == null || fieldValue.getValue() == null) {
    +            return Collections.emptyList();
    +        }
    +        if (!Filters.isRecord(fieldValue)) {
    +            return Collections.emptyList();
    +        }
    +
    +        final Record record = (Record) fieldValue.getValue();
    --- End diff --
    
    As with #2122, I believe ``record`` could be null, no? Might be a good idea to check if it's null and if yes, return an empty collection?


---