You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "KalmanJantner (via GitHub)" <gi...@apache.org> on 2023/01/27 15:42:25 UTC

[GitHub] [nifi] KalmanJantner opened a new pull request, #6899: NIFI-10953: fix default value and update docs

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

   <!-- 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] KalmanJantner commented on pull request #6899: NIFI-11123: fix default value and update docs

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

   > Instead of relying on a parameter context for the output bucket we could add a property on the processor. For that property and the incoming flowfile attributes we could build a custom map and add that as parameter to the `evaluateAttributeExpression` call when getting the value of the payload JSON. When both the property and a similar flowfile attribute is set, flowfile attributes should have precedence.
   > 
   > Also the type of Vision action (like `DOCUMENT_TEXT_DETECTION`) could come from a property as well.
   
   Thank you for the suggestion. I have updated the PR based on your suggestion.


-- 
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] tpalfy commented on pull request #6899: NIFI-11123: fix default value and update docs

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

   LGTM
   Thank you for your work @KalmanJantner and @exceptionfactory for your review!
   Merged into main.


-- 
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] KalmanJantner commented on a diff in pull request #6899: NIFI-11123: fix default value and update docs

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


##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/StartGcpVisionAnnotateFilesOperation.java:
##########
@@ -56,12 +56,12 @@ public class StartGcpVisionAnnotateFilesOperation extends AbstractStartGcpVision
                     "                \"mimeType\": \"application/pdf\"\n" +
                     "            },\n" +
                     "            \"features\": [{\n" +
-                    "                    \"type\": \"DOCUMENT_TEXT_DETECTION\",\n" +
+                    "                    \"type\": \"${feature-type}\",\n" +

Review Comment:
   Thanks fixed.



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/StartGcpVisionAnnotateImagesOperation.java:
##########
@@ -55,21 +55,21 @@ public class StartGcpVisionAnnotateImagesOperation extends AbstractStartGcpVisio
                     "            }\n" +
                     "        },\n" +
                     "        \"features\": [{\n" +
-                    "            \"type\": \"FACE_DETECTION\",\n" +
+                    "            \"type\": \"${feature-type}\",\n" +

Review Comment:
   Thanks fixed.



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/resources/docs/org.apache.nifi.processors.gcp.vision.StartGcpVisionAnnotateFilesOperation/additionalDetails.html:
##########
@@ -55,12 +55,12 @@ <h3>Payload</h3>
                 "mimeType": "application/pdf"
             },
             "features": [{
-                    "type": "DOCUMENT_TEXT_DETECTION",
+                    "type": "${feature-type}",

Review Comment:
   Thanks fixed.



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/resources/docs/org.apache.nifi.processors.gcp.vision.StartGcpVisionAnnotateImagesOperation/additionalDetails.html:
##########
@@ -53,13 +53,13 @@ <h3>Payload</h3>
 			}
 		},
 		"features": [{
-			"type": "DOCUMENT_TEXT_DETECTION",
+			"type": "${feature-type}",

Review Comment:
   Thanks fixed.



-- 
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] exceptionfactory commented on pull request #6899: NIFI-10953: fix default value and update docs

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

   One additional note, these changes should reference a new Jira issue, not the existing Jira issue, which is already resolved.


-- 
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] tpalfy commented on pull request #6899: NIFI-11123: fix default value and update docs

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

   Instead of relying on a parameter context for the output bucket we could add a property on the processor.
   For that property and the incoming flowfile attributes we could build a custom map and add that as parameter to the `evaluateAttributeExpression` call when getting the value of the payload JSON.
   When both the property and a similar flowfile attribute is set, flowfile attributes should have precedence.
   
   Also the type of Vision action (like `DOCUMENT_TEXT_DETECTION`) could come from a property as well.


-- 
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] KalmanJantner commented on pull request #6899: NIFI-11123: fix default value and update docs

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

   > One additional note, these changes should reference a new Jira issue, not the existing Jira issue, which is already resolved.
   
   Thanks, I have created a new ticket and updated the PR desc and title according to that.


-- 
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] exceptionfactory commented on a diff in pull request #6899: NIFI-11123: fix default value and update docs

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


##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -70,7 +92,15 @@ public void onStopped() throws IOException {
     }
 
     private InputStream getInputStreamFromProperty(ProcessContext context, FlowFile flowFile) {
-        return new ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor()).evaluateAttributeExpressions(flowFile).getValue().getBytes(StandardCharsets.UTF_8));
+        Map<String, String> attributes = new HashMap<>();
+        attributes.put(OUTPUT_BUCKET.getName(), getAttributeValue(context, flowFile, OUTPUT_BUCKET.getName()));
+        attributes.put(FEATURE_TYPE.getName(), getAttributeValue(context, flowFile, FEATURE_TYPE.getName()));
+        return new ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor())
+                .evaluateAttributeExpressions(flowFile, attributes).getValue().getBytes(StandardCharsets.UTF_8));
+    }
+
+    private String getAttributeValue(ProcessContext context, FlowFile flowFile, String name) {
+        return flowFile.getAttribute(name) != null ? flowFile.getAttribute(name) : context.getProperty(name).evaluateAttributeExpressions().getValue();

Review Comment:
   It would be helpful to split this into multiple lines for improved readability, and adjust the logical operator. The `evaluateAttributeExpressions()` invocation does not add much value in this case, so it seems unnecessary.
   ```suggestion
           final String flowFileAttribute = flowFile.getAttribute(name);
           final PropertyValue propertyValue = context.getProperty(name);
           return flowFileAttribute == null ? propertyValue.getValue() : flowFileAttribute;
   ```



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -24,14 +24,36 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
 import org.apache.nifi.flowfile.FlowFile;
 import org.apache.nifi.processor.ProcessContext;
 import org.apache.nifi.processor.ProcessSession;
 import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
 
 public abstract class AbstractStartGcpVisionOperation<B extends com.google.protobuf.GeneratedMessageV3.Builder<B>> extends AbstractGcpVisionProcessor  {
+    public static final PropertyDescriptor FEATURE_TYPE = new PropertyDescriptor.Builder()
+            .name("feature-type")
+            .displayName("Vision Feature Type")
+            .description("Type of GCP Vision Feature")
+            .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
+            .required(false)
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .defaultValue("TEXT_DETECTION")
+            .build();
+    public static final PropertyDescriptor OUTPUT_BUCKET = new PropertyDescriptor.Builder()
+            .name("output-bucket")
+            .displayName("Output Bucket")
+            .description("Name of the GCS bucket where the output of the Vision job will be persisted.")

Review Comment:
   As with the Vision Feature Type property, recommend describing when this property applies.
   ```suggestion
               .description("Name of the GCS bucket where the output of the Vision job will be persisted. The value of this property applies when the JSON Payload property is configured. The JSON Payload property value can use Expression Language to reference the value of ${output-bucket}")
   ```



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -24,14 +24,36 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
 import org.apache.nifi.flowfile.FlowFile;
 import org.apache.nifi.processor.ProcessContext;
 import org.apache.nifi.processor.ProcessSession;
 import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
 
 public abstract class AbstractStartGcpVisionOperation<B extends com.google.protobuf.GeneratedMessageV3.Builder<B>> extends AbstractGcpVisionProcessor  {
+    public static final PropertyDescriptor FEATURE_TYPE = new PropertyDescriptor.Builder()
+            .name("feature-type")
+            .displayName("Vision Feature Type")
+            .description("Type of GCP Vision Feature")

Review Comment:
   The description should be updated to indicate that this is only used in evaluation of the JSON Payload.
   ```suggestion
               .description("Type of GCP Vision Feature. The value of this property applies when the JSON Payload property is configured. The JSON Payload property value can use Expression Language to reference the value of ${vision-feature-type}")
   ```



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -70,7 +92,15 @@ public void onStopped() throws IOException {
     }
 
     private InputStream getInputStreamFromProperty(ProcessContext context, FlowFile flowFile) {
-        return new ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor()).evaluateAttributeExpressions(flowFile).getValue().getBytes(StandardCharsets.UTF_8));
+        Map<String, String> attributes = new HashMap<>();
+        attributes.put(OUTPUT_BUCKET.getName(), getAttributeValue(context, flowFile, OUTPUT_BUCKET.getName()));
+        attributes.put(FEATURE_TYPE.getName(), getAttributeValue(context, flowFile, FEATURE_TYPE.getName()));
+        return new ByteArrayInputStream(context.getProperty(getJsonPayloadPropertyDescriptor())
+                .evaluateAttributeExpressions(flowFile, attributes).getValue().getBytes(StandardCharsets.UTF_8));

Review Comment:
   Splitting this declaration into multiple lines would make it easier to follow.
   ```suggestion
           final PropertyValue jsonPropertyValue = context.getProperty(getJsonPayloadPropertyDescriptor());
           final String jsonPayload = jsonPropertyValue.evaluateAttributeExpressions(flowFile, attributes).getValue();
           return new ByteArrayInputStream(jsonPayload.getBytes(StandardCharsets.UTF_8));
   ```



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/AbstractStartGcpVisionOperation.java:
##########
@@ -24,14 +24,36 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
 import org.apache.nifi.annotation.lifecycle.OnStopped;
 import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.expression.ExpressionLanguageScope;
 import org.apache.nifi.flowfile.FlowFile;
 import org.apache.nifi.processor.ProcessContext;
 import org.apache.nifi.processor.ProcessSession;
 import org.apache.nifi.processor.exception.ProcessException;
+import org.apache.nifi.processor.util.StandardValidators;
 
 public abstract class AbstractStartGcpVisionOperation<B extends com.google.protobuf.GeneratedMessageV3.Builder<B>> extends AbstractGcpVisionProcessor  {
+    public static final PropertyDescriptor FEATURE_TYPE = new PropertyDescriptor.Builder()
+            .name("feature-type")

Review Comment:
   Recommend aligning the name and display name:
   ```suggestion
               .name("vision-feature-type")
   ```



-- 
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] exceptionfactory commented on a diff in pull request #6899: NIFI-11123: fix default value and update docs

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


##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/StartGcpVisionAnnotateImagesOperation.java:
##########
@@ -55,21 +55,21 @@ public class StartGcpVisionAnnotateImagesOperation extends AbstractStartGcpVisio
                     "            }\n" +
                     "        },\n" +
                     "        \"features\": [{\n" +
-                    "            \"type\": \"FACE_DETECTION\",\n" +
+                    "            \"type\": \"${feature-type}\",\n" +

Review Comment:
   ```suggestion
                       "            \"type\": \"${vision-feature-type}\",\n" +
   ```



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/vision/StartGcpVisionAnnotateFilesOperation.java:
##########
@@ -56,12 +56,12 @@ public class StartGcpVisionAnnotateFilesOperation extends AbstractStartGcpVision
                     "                \"mimeType\": \"application/pdf\"\n" +
                     "            },\n" +
                     "            \"features\": [{\n" +
-                    "                    \"type\": \"DOCUMENT_TEXT_DETECTION\",\n" +
+                    "                    \"type\": \"${feature-type}\",\n" +

Review Comment:
   This needs to be adjusted to `vision-feature-type`:
   ```suggestion
                       "                    \"type\": \"${vision-feature-type}\",\n" +
   ```



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/resources/docs/org.apache.nifi.processors.gcp.vision.StartGcpVisionAnnotateImagesOperation/additionalDetails.html:
##########
@@ -53,13 +53,13 @@ <h3>Payload</h3>
 			}
 		},
 		"features": [{
-			"type": "DOCUMENT_TEXT_DETECTION",
+			"type": "${feature-type}",

Review Comment:
   ```suggestion
   			"type": "${vision-feature-type}",
   ```



##########
nifi-nar-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/resources/docs/org.apache.nifi.processors.gcp.vision.StartGcpVisionAnnotateFilesOperation/additionalDetails.html:
##########
@@ -55,12 +55,12 @@ <h3>Payload</h3>
                 "mimeType": "application/pdf"
             },
             "features": [{
-                    "type": "DOCUMENT_TEXT_DETECTION",
+                    "type": "${feature-type}",

Review Comment:
   ```suggestion
                       "type": "${vision-feature-type}",
   ```



-- 
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] tpalfy commented on pull request #6899: NIFI-11123: fix default value and update docs

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

   LGTM
   @exceptionfactory if you are okay with the recent changes I'll merge into main.


-- 
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 #6899: NIFI-11123: fix default value and update docs

Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #6899: NIFI-11123: fix default value and update docs
URL: https://github.com/apache/nifi/pull/6899


-- 
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