Re: [PR] NIFI-12773: Added join and anchored RecordPath function [nifi]

2024-02-28 Thread via GitHub


asfgit closed pull request #8391: NIFI-12773: Added join and anchored 
RecordPath function
URL: https://github.com/apache/nifi/pull/8391


-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] NIFI-12773: Added join and anchored RecordPath function [nifi]

2024-02-20 Thread via GitHub


markap14 commented on PR #8391:
URL: https://github.com/apache/nifi/pull/8391#issuecomment-1955158350

   @ChrisSamo632 thanks for reviewing. Pushed a new commit that addresses your 
comments above.


-- 
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-unsubscr...@nifi.apache.org

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



Re: [PR] NIFI-12773: Added join and anchored RecordPath function [nifi]

2024-02-16 Thread via GitHub


ChrisSamo632 commented on code in PR #8391:
URL: https://github.com/apache/nifi/pull/8391#discussion_r1492937244


##
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Anchored.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.StandardRecordPathEvaluationContext;
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+import org.apache.nifi.serialization.record.Record;
+
+import java.util.Arrays;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+public class Anchored extends RecordPathSegment {
+
+private final RecordPathSegment anchorPath;
+private final RecordPathSegment evaluationPath;
+
+public Anchored(final RecordPathSegment anchorPath, final 
RecordPathSegment evaluationPath, final boolean absolute) {
+super("anchored", null, absolute);
+
+this.anchorPath = anchorPath;
+this.evaluationPath = evaluationPath;
+}
+
+
+@Override
+public Stream evaluate(final RecordPathEvaluationContext 
context) {
+final Stream anchoredStream = anchorPath.evaluate(context);
+
+return anchoredStream.flatMap(fv -> {
+final Object value = fv.getValue();
+return evaluate(value);
+});
+}
+
+private Stream evaluate(final Object value) {
+if (value == null) {
+return Stream.of();
+}
+if (value instanceof Record) {
+final RecordPathEvaluationContext recordPathEvaluateContext = new 
StandardRecordPathEvaluationContext((Record) value);
+return evaluationPath.evaluate(recordPathEvaluateContext);
+}
+if (value instanceof final Record[] array) {
+return Arrays.stream(array).flatMap(element -> {
+final RecordPathEvaluationContext recordPathEvaluateContext = 
new StandardRecordPathEvaluationContext(element);
+return evaluationPath.evaluate(recordPathEvaluateContext);
+});
+}
+if (value instanceof final Iterable iterable) {
+return StreamSupport.stream(iterable.spliterator(), 
false).flatMap(element -> {
+if (!(element instanceof Record)) {
+return Stream.of();
+}
+
+final RecordPathEvaluationContext recordPathEvaluateContext = 
new StandardRecordPathEvaluationContext((Record) element);
+return evaluationPath.evaluate(recordPathEvaluateContext);

Review Comment:
   These lines are duplicated, albeit they're fairly trivial, but would it be 
better to create an `evaluateRecordFieldValue` method to be used by each `if` 
block here?



##
nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/Anchored.java:
##
@@ -0,0 +1,80 @@
+/*
+ * 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.StandardRecordPathEvaluationContext;
+import org.apache.nifi.record.path.paths.RecordPathSegment;
+import org.apache.nifi.serialization.record.Record;
+
+import 

Re: [PR] NIFI-12773: Added join and anchored RecordPath function [nifi]

2024-02-12 Thread via GitHub


ChrisSamo632 commented on code in PR #8391:
URL: https://github.com/apache/nifi/pull/8391#discussion_r1486862504


##
nifi-docs/src/main/asciidoc/record-path-guide.adoc:
##
@@ -456,6 +456,48 @@ Concatenates all the arguments together.
 |==
 
 
+=== join
+
+Joins together multiple values with a separator.
+
+|==
+| RecordPath | Return value
+| `join(', ', /workAddress/* )` | 123, 5th Avenue, New York, NY, 10020
+|==
+
+
+=== anchored
+
+Allows evaluating a RecordPath while anchoring the root context to a child 
record.
+
+|==
+| RecordPath | Return value
+| `anchored(/homeAddress, /city)` | Jersey City
+|==
+
+Additionally, this can be 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 can evaluate hte following Record paths:

Review Comment:
   ```suggestion
   We can evaluate the following Record paths:
   ```



-- 
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-unsubscr...@nifi.apache.org

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



[PR] NIFI-12773: Added join and anchored RecordPath function [nifi]

2024-02-09 Thread via GitHub


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

   
   
   
   
   
   
   
   
   
   
   
   
   
   # Summary
   
   [NIFI-0](https://issues.apache.org/jira/browse/NIFI-0)
   
   # 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-0`
   - [ ] Pull Request commit message starts with Apache NiFi Jira issue number, 
as such `NIFI-0`
   
   ### 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 21
   
   ### 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-unsubscr...@nifi.apache.org

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