[NIFI-10754] Initial check in of new getUri NIFI Expression Language …#6689
[NIFI-10754] Initial check in of new getUri NIFI Expression Language …#6689dan-s1 wants to merge 3 commits intoapache:mainfrom
Conversation
|
@exceptionfactory If you have time, can you please review this in order for this to get into 1.19? |
|
Thanks the contribution @dan-s1, the general approach makes sense on a cursory review, but I would like to take a closer look, so I don't think this will make it in to 1.19.0. |
|
@exceptionfactory Now that 1.19.0 has been released, when you have some time can you please review this? |
|
@exceptionfactory Wondering if this could be revisited. It is functionality my team could use. Thanks! |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for working on this new feature @dan-s1. Although most of the implementation makes sense, it raises some questions about treating blanks strings as nulls. Although the java.net.URI has a number of constructors, it seems like this may provide more options than necessary. There is some value in simplicity, versus exposing all the possible options, which could also avoid potential confusion related to handling blank strings as nulls.
The discussion on NIFI-10754 originated out of issues with the urlEncode function. If the implementation were to be scoped down to just something like uriEncodePath, for instance, would that provide the desired functionality?
| public QueryResult<String> evaluate(EvaluationContext evaluationContext) { | ||
| List<String> args = Arrays.stream(uriArgs) | ||
| .map(uriArg -> uriArg.evaluate(evaluationContext).getValue()) | ||
| .map(string -> StringUtils.isBlank(string) ? null : string) |
There was a problem hiding this comment.
The StringUtils.isBlank() check would convert both empty strings such as "" as well as strings with spaces such as " " to null. Although these seem to be unlikely arguments, it raises a larger question about passing empty arguments. The check should probably be simplified to check for an empty string:
| .map(string -> StringUtils.isBlank(string) ? null : string) | |
| .map(string -> string == null || string.isEmpty() ? null : string) |
@exceptionfactory If I understand you correctly that means there would have to be potentially at least 3 method calls when constructing a URI, one to urlEncodePath to encode the path, one to urlEncode to encode the parameters and one to concatenate all the strings necessary for creating the URI . I was actually intending to simplify that process of URI construction with one call which would take care of the encoding for both the path and the parameters and building the URI. |
|
Thanks for clarifying the intent @dan-s1, constructing the complete URI in a single function makes sense. With that background, do you need all of the possible constructor options? It might be simpler to support just one or two options, as opposed to all of the convenience constructors. To the other question, is there a possibility that an empty string should be allowed as an argument instead of treated as |
That is a hard call because I am not sure what different people need.
Per the URI javadocs
I did not see a way of explicitly passing null except if a blank string was passed. Please let me know otherwise if null can be passed. |
|
Thanks for the reply @dan-s1. As you observed, the Expression Language parser does not support a literal For For hierarchical URIs, the four and five argument constructors appear to fall into the convenience category. For simplicity of the initial implementation, what do you think of limiting the implementation to the seven argument constructor? Although it is the most verbose, it provides the clearest implementation for documentation and usage. |
|
@exceptionfactory I am fine with only implementing the seven argument constructor. What did you have in mind for implementing a literal null as a function argument? I only question if it is more clearer than specifying to users to use an empty string which we can convert to null on the back end. |
I was thinking that An empty string could be passed to any of the string arguments, but allowing a |
|
@exceptionfactory I added the null literal as you requested and modified the documentation to reflect this. Please let me know if my changes are what you were intending. Thanks! |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for making the adjustments @dan-s1, this looks close to completion. I noted one more substantive change, breaking out the URI constructor arguments and port parsing to make the code more readable.
...java/org/apache/nifi/attribute/expression/language/evaluation/functions/GetUriEvaluator.java
Outdated
Show resolved
Hide resolved
… in a URI, constructed an instance of java.net.URI with those variables and placed parsing of port argument in its own method.
|
@exceptionfactory I noticed on my latest changes, the build ci-workflow / Ubuntu Zulu JDK 11 HI failed but it failed on a unit test unrelated to my changes. The unit test which failed is |
|
The latest PR build appears to be working as expected, it sounds like the other issues were unrelated intermittent failures. |
|
@exceptionfactory Is there anything else that needs to be done for this PR? |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for working through the feedback @dan-s1, the latest version looks good from a code and functional perspective. I noticed a minor documentation formatting issue with the first example expression usage, but I will correct that in the merge commit. +1 merging
…function.
Summary
NIFI-10754
Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000Pull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
mvn clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation