Skip to content

NIFI-4142: Refactored Record Reader/Writer to allow for reading/writi…#2015

Closed
markap14 wants to merge 1 commit intoapache:masterfrom
markap14:NIFI-4142
Closed

NIFI-4142: Refactored Record Reader/Writer to allow for reading/writi…#2015
markap14 wants to merge 1 commit intoapache:masterfrom
markap14:NIFI-4142

Conversation

@markap14
Copy link
Contributor

…ng "raw records". Implemented ValidateRecord.

Thank you for submitting a contribution to Apache NiFi.

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?

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.


public class TypeMismatchException extends RuntimeException {
Copy link
Contributor

Choose a reason for hiding this comment

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

i dont think it is ok to change this exeception class name at this juncture and even if it is questionable ok the juice is probably not worth the squeeze. TypeMismatch and SchemaValidation are pretty much the same thing

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 don't agree that they are pretty much the same thing. TypeMismatchException is very specific. SchemaValidationException can be much more broad. For instance, if a required field is missing, that is not a Type Mismatch, but it is a Schema Validation.

* @throws SchemaValidationException if a Record contains a field that violates the schema and cannot be coerced into the appropriate
* field type and schema enforcement is enabled
*/
Record nextRecord(boolean enforceSchema) throws IOException, MalformedRecordException;
Copy link
Contributor

Choose a reason for hiding this comment

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

the schema had always been enforced arguably just with sense of leniency. I think this method parameter should be 'strictSchemaEnforcement' or 'enforceStrictSchema'.

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 think I actually want to just separate the concept out into two different variables here: boolean coerceTypes, boolean dropUnknownRecords. That way it is very explicit what is happening, and I don't think that 'strict' vs. 'lenient' really conveys those two semantics as well as I'd like.

* @throws SchemaValidationException if a Record contains a field that violates the schema and cannot be coerced into the appropriate field type.
*/
Record nextRecord() throws IOException, MalformedRecordException;
default Record nextRecord() throws IOException, MalformedRecordException {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should indicate whether the scheme enforcement strictness is 'lenient' or 'strict'.

@markap14
Copy link
Contributor Author

@joewitt I've pushed a new commit that I believe better clarifies how schemas are treated in terms of strictness vs. leniency by providing two arguments instead of 'enforceSchema': 'coerceTypes' and 'dropUnknownFields'

@joewitt
Copy link
Contributor

joewitt commented Aug 11, 2017

@markap14 can you please rebase and resolve conflict and please go ahead and squash.

…ng "raw records". Implemented ValidateRecord. Updated Record Reader to take two parameters for nextRecord: (boolean coerceTypes) and (boolean dropUnknownFields)
@joewitt
Copy link
Contributor

joewitt commented Aug 11, 2017

@markap14 looks like the option says "Used Reader's Schema". I'm assuming that is a typo and it should say "Use Reader's Schema". But that is not in this PR it appears. Did that sneak in elsewhere?

"The schema to validate the data against is determined by looking at the 'Schema Name' Property and looking up the schema in the configured Schema Registry");
static final AllowableValue SCHEMA_TEXT_PROPERTY = new AllowableValue("schema-text-property", "Use Schema Text Property",
"The schema to validate the data against is determined by looking at the 'Schema Text' Property and parsing the schema as an Avro schema");
static final AllowableValue READER_SCHEMA = new AllowableValue("reader-schema", "Used Reader's Schema",
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah here it is. "Used Reader's Schema" should be "Use Reader Schema".

@joewitt
Copy link
Contributor

joewitt commented Aug 12, 2017

went ahead and fixed the typo and squashed locally.

Ran a test flow that created csv of various conformity to a simple spec. Ran it through various configratuions of the validator and it behaved as desired and expected in each case. When data was marked invalid was able to see precisely why through the provenance events which was great. Was able to see coercion/non-coercion behavior and all checks out.

+1 merging to master

@asfgit asfgit closed this in 451f9cf Aug 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants