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

Fix Seq Validation #219

Merged
merged 5 commits into from
Mar 1, 2022
Merged

Fix Seq Validation #219

merged 5 commits into from
Mar 1, 2022

Conversation

jackdingilian
Copy link
Contributor

@jackdingilian jackdingilian commented Feb 28, 2022

The current approach to Seq validation fails on Seqs containing nested records when it tries to get the ValidationType name from the nested record. It needs the ValidationType name in order to publish metrics. To avoid this problem this splits the field level validation logic into its own function that writes the metrics. This can then be re-used from DerivedValidator and SeqLikeValidator against any FieldValidator

I benchmarked this against master and there was no performance degradation (it was actually a bit faster but might just be variance)


import com.spotify.elitzur.{DataInvalidException, IllegalValidationException, MetricsReporter}
import java.lang.{StringBuilder => JStringBuilder}
import com.spotify.elitzur.{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, running scalafmt on this made it seem like a much larger change. The material changes are in SeqLikeValidator (line 184), validationLoop (line 327), and validateField (line 424)

@@ -0,0 +1,207 @@
package com.spotify.elitzur.validators
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 some of our core tests got dropped when we open sourced. Adding some simple testing here so we aren't relying on ValidatorDoFnTest as much

Copy link
Contributor

@idreeskhan idreeskhan left a comment

Choose a reason for hiding this comment

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

Hard to parse the details with the scalafmt changes but looks intuitive to me

@@ -125,6 +125,7 @@ object CaseClassValidators {
val fiveNFiveVal: Validator[FiveNestedFiveFields] = genFiveNestedFive()
}

//scalastyle:off magic.number
Copy link
Contributor

Choose a reason for hiding this comment

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

Need a correspond on toggle

@jackdingilian jackdingilian merged commit 462268a into master Mar 1, 2022
@jackdingilian jackdingilian deleted the fix-seq-validation branch March 1, 2022 15:04
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