Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

travisneeley
Copy link
Contributor

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:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

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.

@YolandaMDavis
Copy link
Contributor

YolandaMDavis commented Jul 12, 2019

@travisneeley I can take a look

@YolandaMDavis
Copy link
Contributor

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

See https://github.com/travisneeley/nifi/blob/NIFI-6417/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/main/java/org/apache/nifi/web/standard/api/transformjson/TransformJSONResource.java#L63

Compared to:
https://github.com/travisneeley/nifi/blob/NIFI-6417/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/JoltTransformJSON.java#L371

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(),
Copy link
Contributor

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

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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);
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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

@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Apr 25, 2021
@github-actions github-actions bot closed this May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants