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

Implemented data validation on the backend #2

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

rpolyano
Copy link
Owner

This approach creates an error collector analog at wrangle-time, which can also be reused by other directives that want to draw user attention to error rows.

@@ -0,0 +1,68 @@
/*
* Copyright © 2017-2019 Cask Data, Inc.

Choose a reason for hiding this comment

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

copyright only needs 2019

@@ -37,7 +38,10 @@
// Values held by the row.
private List<Object> values = new ArrayList<>();

private final UUID id;

Choose a reason for hiding this comment

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

it doesn't look like the id is used anywhere. It would be better to add it later if required instead of right now.

protected final List<Object> causes;

public ErrorRecordBase(
String message, int code, boolean showInWrangler, List<Object> causes) {

Choose a reason for hiding this comment

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

the CDAP related projects (including wrangler) use a checkstyle that only requires lines to be within 120 characters and not 80, so these could all be on the previous line.

.stream()
.filter(ErrorRecord::isShownInWrangler)
// Use slim error record to reduce message size.
.map(SlimErrorRecord::new)

Choose a reason for hiding this comment

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

is the eventual response eventually serialized as a SlimErrorRecord? I would think it gets serialized as an ErrorRecordBase since that's what's returned by ErrorRecordsException.getErrorRecords()?

Copy link
Owner Author

Choose a reason for hiding this comment

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

It gets serialized as SlimErrorRecord, since that's the actual type.

// Code associated with the message.
protected final int code;
protected final boolean showInWrangler;
protected final List<Object> causes;

Choose a reason for hiding this comment

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

I think it would be better for causes to have a defined structure rather than allow any object. Object, for example, would allow somebody to use a mix of primitives, objects, collections, etc.

This is probably a larger discussion, and the causes don't seem to be used yet so it may be better to remove this and add it back later when there's a more concrete idea of how it will be used.

Copy link
Owner Author

Choose a reason for hiding this comment

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

This depends on the frontend actually. Originally I wanted to put Exceptions/Throwables here, but it's probably not useful to hold a stacktrace and all that. Perhaps we should make a common base class that contains some data pointer and a message and then ValidationIssue is an extension of that with a schema pointer?

Choose a reason for hiding this comment

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

It will probably end up something like that, with an actual Cause class that either allows users to extend it with arbitrary data, or contains some map of properties that users populate, or something like that. Since there are still open questions about what exactly is needed here and how it will be used, this should be added in the future. Anything we add in wrangler-api cannot be removed/changed without deprecating it for the entirety of a major release.

@@ -0,0 +1,76 @@
/*
* Copyright © 2019 Google Inc.

Choose a reason for hiding this comment

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

copyright here is different from other files

private final List<ErrorRecordBase> errorRecords;

public ErrorRecordsException(List<ErrorRecordBase> errorRecords) {
super(String.format("%d error records were produced", errorRecords.size()));

Choose a reason for hiding this comment

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

With the assumption that nothing in the UI is changing, it makes sense to also include the message of the first error in the exception message (or the first X errors, or the first N characters?), otherwise there will be no way to know what to correct. I would just avoid showing them all, as it could easily become a huge message that covers the entire screen.

I think if we were to change the UI, we would also want to do the full solution in the backend where all errors are collected and returned, rather than this intermediate solution.

CuriousVini and others added 6 commits September 3, 2019 10:54
…re/improve-directive-error

Remove usage of toString() from directive error messages
…x/CDAP-15541-null-error-message

[CDAP-15541] fix error message when there is schema mismatch
…end-to-error

Fix error message assert in unit tests
@rpolyano rpolyano force-pushed the feature/data-models-2 branch 2 times, most recently from 6dbacf6 to 073fad2 Compare September 6, 2019 19:55
@rpolyano rpolyano force-pushed the feature/data-models-2 branch from 073fad2 to bc4464f Compare September 9, 2019 15:35
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.

4 participants