You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2022/12/12 19:43:56 UTC

[GitHub] [nifi] markap14 opened a new pull request, #6778: NIFI-10970: Added a count RecordPath function

markap14 opened a new pull request, #6778:
URL: https://github.com/apache/nifi/pull/6778

   <!-- 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. -->
   
   # Summary
   
   [NIFI-00000](https://issues.apache.org/jira/browse/NIFI-00000)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [ ] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [ ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [ ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [ ] Pull Request based on current revision of the `main` branch
   - [ ] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `mvn clean install -P contrib-check`
     - [ ] JDK 8
     - [ ] JDK 11
     - [ ] JDK 17
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] markap14 commented on a diff in pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by "markap14 (via GitHub)" <gi...@apache.org>.
markap14 commented on code in PR #6778:
URL: https://github.com/apache/nifi/pull/6778#discussion_r1084257475


##########
nifi-docs/src/main/asciidoc/record-path-guide.adoc:
##########
@@ -1071,6 +1071,37 @@ take the value of the supplied record path and use it as the namespace.
 Please note that the namespace must always be a valid UUID string. An empty string, another data type, etc. will result
 in an error. This is by design because the most common use case for UUID v5 is to uniquely identify records across data sets.
 
+
+=== count
+
+Returns the count of the number of elements. This is commonly used in conjunction with arrays. For example, if we have the following record:
+
+----
+{
+    "id": "1234",
+    "elements": [{
+        "name": "book",
+        "color": "red"
+    }, {
+        "name": "computer",
+        "color": "black"
+    }]
+}
+----
+
+We could determine the number of `elements` by using the `count` function. Using:
+
+----
+count(/elements[*])
+----
+
+Would yield a value of `2`. We could also use this as a filter, such as:
+----
+/id[ count(/elements[*]) ]

Review Comment:
   Good catch



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] markap14 commented on pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by "markap14 (via GitHub)" <gi...@apache.org>.
markap14 commented on PR #6778:
URL: https://github.com/apache/nifi/pull/6778#issuecomment-1400616931

   Thanks @MikeThomsen and @ChrisSamo632 addressed both of those.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] ChrisSamo632 commented on a diff in pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on code in PR #6778:
URL: https://github.com/apache/nifi/pull/6778#discussion_r1058952730


##########
nifi-docs/src/main/asciidoc/record-path-guide.adoc:
##########
@@ -1071,6 +1071,37 @@ take the value of the supplied record path and use it as the namespace.
 Please note that the namespace must always be a valid UUID string. An empty string, another data type, etc. will result
 in an error. This is by design because the most common use case for UUID v5 is to uniquely identify records across data sets.
 
+
+=== count
+
+Returns the count of the number of elements. This is commonly used in conjunction with arrays. For example, if we have the following record:
+
+----
+{
+    "id": "1234",
+    "elements": [{
+        "name": "book",
+        "color": "red"
+    }, {
+        "name": "computer",
+        "color": "black"
+    }]
+}
+----
+
+We could determine the number of `elements` by using the `count` function. Using:
+
+----
+count(/elements[*])
+----
+
+Would yield a value of `2`. We could also use this as a filter, such as:
+----
+/id[ count(/elements[*]) ]

Review Comment:
   This would reflect the unit test you've written with a `> 2` example



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] asfgit closed pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #6778: NIFI-10970: Added a count RecordPath function
URL: https://github.com/apache/nifi/pull/6778


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] ChrisSamo632 commented on a diff in pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on code in PR #6778:
URL: https://github.com/apache/nifi/pull/6778#discussion_r1058951771


##########
nifi-docs/src/main/asciidoc/record-path-guide.adoc:
##########
@@ -1071,6 +1071,37 @@ take the value of the supplied record path and use it as the namespace.
 Please note that the namespace must always be a valid UUID string. An empty string, another data type, etc. will result
 in an error. This is by design because the most common use case for UUID v5 is to uniquely identify records across data sets.
 
+
+=== count
+
+Returns the count of the number of elements. This is commonly used in conjunction with arrays. For example, if we have the following record:
+
+----
+{
+    "id": "1234",
+    "elements": [{
+        "name": "book",
+        "color": "red"
+    }, {
+        "name": "computer",
+        "color": "black"
+    }]
+}
+----
+
+We could determine the number of `elements` by using the `count` function. Using:
+
+----
+count(/elements[*])
+----
+
+Would yield a value of `2`. We could also use this as a filter, such as:
+----
+/id[ count(/elements[*]) ]

Review Comment:
   ```suggestion
   /id[ count(/elements[*]) = 2]
   ```
   
   Presumably for this to be a [filter function](https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html#filters), there needs to be some sort of [predicate](https://nifi.apache.org/docs/nifi-docs/html/record-path-guide.html#predicates), worth reflecting that within the docs



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] MikeThomsen commented on a diff in pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by GitBox <gi...@apache.org>.
MikeThomsen commented on code in PR #6778:
URL: https://github.com/apache/nifi/pull/6778#discussion_r1047383469


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Count.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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 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;
+import org.apache.nifi.serialization.record.RecordField;
+import org.apache.nifi.serialization.record.RecordFieldType;
+
+import java.util.stream.Stream;
+
+public class Count extends RecordPathSegment {
+    private final RecordPathSegment recordPath;
+
+    public Count(final RecordPathSegment recordPath, final boolean absolute) {
+        super("replace", null, absolute);

Review Comment:
   Shouldn't the first parameter be `count`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] markap14 commented on a diff in pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by "markap14 (via GitHub)" <gi...@apache.org>.
markap14 commented on code in PR #6778:
URL: https://github.com/apache/nifi/pull/6778#discussion_r1084256440


##########
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Count.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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 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;
+import org.apache.nifi.serialization.record.RecordField;
+import org.apache.nifi.serialization.record.RecordFieldType;
+
+import java.util.stream.Stream;
+
+public class Count extends RecordPathSegment {
+    private final RecordPathSegment recordPath;
+
+    public Count(final RecordPathSegment recordPath, final boolean absolute) {
+        super("replace", null, absolute);

Review Comment:
   Good catch!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [nifi] joewitt commented on pull request #6778: NIFI-10970: Added a count RecordPath function

Posted by "joewitt (via GitHub)" <gi...@apache.org>.
joewitt commented on PR #6778:
URL: https://github.com/apache/nifi/pull/6778#issuecomment-1400938471

   Yeah seems like his feedback was addressed.  Please do merge or I can later when I sweep through rc1 items again.  Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org