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-6670: Add TextLineReader to read lines of text as single-field records #3735

Closed
wants to merge 2 commits into from

Conversation

mattyb149
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?
  • [] Have you verified that the full build is successful on both JDK 8 and JDK 11?
  • 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.

Copy link
Contributor

@MikeThomsen MikeThomsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working through it, but have some questions/ideas for you consideration.


@Override
protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
final List<PropertyDescriptor> properties = new ArrayList<>(super.getSupportedPropertyDescriptors());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a bit more efficient to create this all at once with a static constructor such as

public static final List<PropertyDescriptor> PROPS = Collections.unmodifiableList(Arrays.asList(.....));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattyb149 can you address this? or reply?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is done differently by different processors, I copied this part of the code from some other RecordReader.

this.linesLeftToSkip = skipLineCount;
this.linesPerGroup = linesPerGroup;
this.ignoreEmptyLines = ignoreEmptyLines;
final List<RecordField> fieldList = Collections.singletonList(new RecordField(fieldName, RecordFieldType.STRING.getDataType()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a default, that's a good one, but there should be some connection to a schema registry so users can do things like specify numeric inputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The benefit here is that you don't need to provide a schema. Otherwise I would think a GrokReader would suffice?

@ottobackwards
Copy link
Contributor

This seems like the kind of thing that would be, or could be used as the base class for other "line by line readers". If this existed before grok reader for example, wouldn't thought go to extending this to implement that?

How easy do you think it would be to inherit from this reader?

@mattyb149 mattyb149 changed the base branch from master to main August 12, 2020 20:15
@mattyb149
Copy link
Contributor Author

This one isn't currently designed to be subclassed (none of the actual component implementations are), but if there is some reusable code (a base class for example) we could consider putting it in the API.

@ottobackwards @MikeThomsen I've updated the PR, rebased against main, and added the additional feature of allowing the entire content to be treated as a record (by setting Lines Per Record to zero), any chance you could review again? Thanks in advance!

final List<RecordField> fieldList = Collections.singletonList(new RecordField(fieldName, RecordFieldType.STRING.getDataType()));
schema = new SimpleRecordSchema(fieldList);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there is no requirement for java doc, but this function is pretty important, and the most likely place for maintainability.

Could you add an overview/summary of the goals, approach, logic and concerns?
It will keep folks like me from messing it up


protected static final PropertyDescriptor IGNORE_EMPTY_LINES = new PropertyDescriptor.Builder()
.name("linereader-ignore-empty-lines")
.displayName("Ignore Empty Lines")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand this. Can you reword and clarify how this relates to other properties?

@@ -0,0 +1,7 @@
Header line 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to test multiple sequential empty lines instead of just a single?

@mattyb149
Copy link
Contributor Author

Closing my PR for now due to inactivity and the fact that you can use a GrokReader with Schema Access Strategy set to "Use String Fields from Grok Expression" (the default) and a Grok Expression of

%{GREEDYDATA:message}

@mattyb149 mattyb149 closed this Mar 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants