-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NIFI-6417 Configurable Jolt Transform Charsets #3576
Conversation
@travisneeley I can take a look |
@travisneeley For this PR, is the goal to allow configurable charsets on the provided specification as well as on the content input/output ? From what I can tell in current changes I see the inputCharset applied to the jolt specification string and the output of the flow file, but not on the incoming json. I'll ensure to add line comments to highlight these areas. Also I see that changes were made for the JoltTransformJSON processor itself but doesn't appear in Advanced UI code: cc: @mattyb149 |
.displayName("Input Character Set") | ||
.description("The encoding character set for the input JSON for transformation") | ||
.required(true) | ||
.allowableValues(StandardCharsets.UTF_8.name(), StandardCharsets.UTF_16.name(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will allowable charset options be the same for input/output properties? If so perhaps this could be a list shared between the two for simplicity (I believe the builder makes internal copies of the values anyway for the property descriptor instance).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree for the most part as most user's aren't going to change the encoding during a Jolt Transformation, I only added the output charset because the ticket requested it.
} | ||
|
||
private JoltTransform createTransform(final ProcessContext context, final String specString) throws Exception { | ||
final Object specJson; | ||
if (context.getProperty(JOLT_SPEC).isSet() && !SORTR.getValue().equals(context.getProperty(JOLT_TRANSFORM).getValue())) { | ||
specJson = JsonUtils.jsonToObject(specString, DEFAULT_CHARSET); | ||
specJson = JsonUtils.jsonToObject(specString, inputCharset.name()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a similar call in the advanced UI that may also need to be addressed for consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I have no idea how to fix that. I have no experience in fixing custom UI pieces in NiFi as I've actively avoided them since I started working with the framework.
Will the Advanced UI respect the processor setting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@travisneeley the advanced UI uses some shared utilities with the processor but not everything, so it would need to be updated as well. In this case you would need to add the input/output charset entry and ensure that the test processor applies those values to test spec as well as test input/output.
I'd be happy to guide you through edits required and how to test if needed (can provide more guidance in comments on the JIRA). The important idea is to ensure it's functionality remains consistent with processor functionality.
@@ -266,7 +294,7 @@ public void onTrigger(final ProcessContext context, ProcessSession session) thro | |||
try (final InputStream in = session.read(original)) { | |||
inputJson = JsonUtils.jsonToObject(in); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I'm wondering inputCharset was supposed to be applied for incoming json data (@mattyb149 any thoughts on this?)? If so I think you may need a bit more manipulation to apply inputChartset before passing to jsonToObject (since it may not support passing inputstream with charset).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, that library supports two methods there - String JSON with String Charset name and InputStream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@travisneeley I had a chat with @mattyb149 offline and he confirmed the intent was to apply changes for incoming json. Given JsonUtils.jsonToObject method doesn't support passing both InputStream and encoding or even allow a reader, it may be reasonable to use a ReaderInputStream (see https://commons.apache.org/proper/commons-io/javadocs/api-release/org/apache/commons/io/input/ReaderInputStream.html).
It does makes sense to also apply to the specification, since transformations can potentially add characters to the result or to simply match content. The same property for the input charset can be applied to both (we can't see a case where a separate charset would be needed for the spec).
We're marking this PR as stale due to lack of updates in the past few months. If after another couple of weeks the stale label has not been removed this PR will be closed. This stale marker and eventual auto close does not indicate a judgement of the PR just lack of reviewer bandwidth and helps us keep the PR queue more manageable. If you would like this PR re-opened you can do so and a committer can remove the stale tag. Or you can open a new PR. Try to help review other PRs to increase PR review bandwidth which in turn helps yours. |
Thank you for submitting a contribution to Apache NiFi.
Please provide a short description of the PR here:
Description of PR
Enables X functionality; fixes bug NIFI-YYYY.
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? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not
squash
or use--force
when pushing to allow for clean monitoring of changes.For code changes:
mvn -Pcontrib-check clean install
at the rootnifi
folder?LICENSE
file, including the mainLICENSE
file undernifi-assembly
?NOTICE
file, including the mainNOTICE
file found undernifi-assembly
?.displayName
in addition to .name (programmatic access) for each of the new properties?For documentation related changes:
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.