Skip to content

[MINOR] Handle cases of malformed records when converting to json#10943

Merged
danny0405 merged 5 commits intoapache:masterfrom
the-other-tim-brown:minor-avro-to-json
Apr 6, 2024
Merged

[MINOR] Handle cases of malformed records when converting to json#10943
danny0405 merged 5 commits intoapache:masterfrom
the-other-tim-brown:minor-avro-to-json

Conversation

@the-other-tim-brown
Copy link
Contributor

Change Logs

Handles cases of missing required fields and bad input values when converting to JSON. This conversion is used in combination with the Error Table so you cannot assume that the records are properly formatted.

Impact

Avoids exceptions being thrown for malformed input data being sent to the error table writer

Risk level (write none, low medium or high below)

None

Documentation Update

Describe any necessary documentation update if there is any new feature, config, or user-facing change. If not, put "none".

  • The config description must be updated if new configs are added or the default value of the configs are changed
  • Any new feature or user-facing change requires updating the Hudi website. Please create a Jira ticket, attach the
    ticket number here and follow the instruction to make
    changes to the website.

Contributor's checklist

  • Read through contributor's guide
  • Change Logs and Impact were stated clearly
  • Adequate tests were added if applicable
  • CI passed

@github-actions github-actions bot added the size:S PR with lines of changes in (10, 100] label Apr 1, 2024
// NullPointerException will be thrown in cases where the field values are missing
// ClassCastException will be thrown in cases where the field values do not match the schema type
// Fallback to using `toString` which also returns json but without a pretty-print option
out.write(record.toString().getBytes(StandardCharsets.UTF_8));
Copy link
Contributor

Choose a reason for hiding this comment

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

What do we get for record.toString when NullPointerException is thrown?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, seems like a null constant for empty field.

Copy link
Contributor

Choose a reason for hiding this comment

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

So when the transformed JSON string got converted back into avro, the schema could change right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You get a string that represents the json of the object, it does not do any validation on types/nullability. See the tests that are added for a sample.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So when the transformed JSON string got converted back into avro, the schema could change right?

The case here is when you have some data and are trying to convert it to avro and it fails. https://github.com/apache/hudi/blob/master/hudi-utilities/src/main/java/org/apache/hudi/utilities/streamer/HoodieStreamerUtils.java#L164

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'm not familiar with that flow. If this is breaking that flow, I can just make a new method

Copy link
Contributor

Choose a reason for hiding this comment

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

If the schema does not really change for that, it is okay, maybe we can add some use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One concern I have is that this could hide some exception and then we don't catch something in our initial testing for some more critical timeline related flow. I think I've convinced myself there should just be a new method like "safeToJson" that does not throw an exception that we use in the error table/writer cases since those are not as critical to Hudi.

Copy link
Contributor

Choose a reason for hiding this comment

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

think I've convinced myself there should just be a new method like "safeToJson" that does not throw an exception that we use in the error table/writer cases since those are not as critical to Hudi.

+1

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've pushed an update

@hudi-bot
Copy link
Collaborator

hudi-bot commented Apr 5, 2024

CI report:

Bot commands @hudi-bot supports the following commands:
  • @hudi-bot run azure re-run the last Azure build

@danny0405 danny0405 merged commit d41541c into apache:master Apr 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S PR with lines of changes in (10, 100]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants