-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
AVRO-2723: Refactor ReflectData to allow derived classes to customize default values for fields #842
Conversation
…hemaDefaultValue()
@sekikn I tried to fix errors with Travis. Would you please to have a look at this error? https://travis-ci.org/apache/avro/jobs/660406896#L38-L41. I don't know how to troubleshoot it. |
That seems an intermittent error and irrelevant to your fix. So just wait for some committer to review your PR or ping them (@Fokko @RyanSkraba could you take a look?). They will rerun the CI if needed.
|
Your PR looks good to me, but unfortunately I'm just an Avro contributor and not a committer. Sorry 😔 |
The implementation looks reasonable to me. Can you please add a test of this new functionality? Thanks! |
@cutting The refectored code does not change the current logic (all tests are passed). So I think the effective scenario is:
Is that ok? |
Yes, that is the sort of test I imagine, a subclass that overrides this new method and a test that validates that the overridden method is called in the expected manner and can achieve the desired effects. |
public int f1 = 55; | ||
public String f2 = "a-string"; | ||
public List<String> f3 = Arrays.asList("one", "two", "three"); | ||
// public User usr = new User(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cutting I commented out this field due to an issue with JacksonUtils as described here https://issues.apache.org/jira/browse/AVRO-2775
The test looks good. It also looks like an implementation that's generally useful and should probably be included in Avro, not just in a test, no? If we're concerned about back-compatibility, we could implement it optionally, e.g., maybe adding a ReflectData#setGenerateDefaults(boolean) method or something. Is there a reason not to make this the default behavior in some future release? |
Actually I did implement such things with suggestions from @sekikn. Please have a look at:
So I decided to put a partial implementation in this PR and gradually resolved my issues. Is that ok? |
I was thinking an attribute of ReflectData rather than a subclass might be
more useful. Then we might consider changing the default behavior in a
future release, since using class-specified defaults seems more natural and
expected.
As for the implementation, we probably shouldn't be printing stack traces,
but rather either rethrowing or silently swallowing them.
I don't see the importance of committing the refactoring without the
implementation if that's the primary imagined implementation.
…On Thu, Apr 9, 2020 at 7:15 PM Anh Le (Andy) ***@***.***> wrote:
@cutting <https://github.com/cutting>
It also looks like an implementation that's generally useful and should
probably be included in Avro, not just in a test, no?
Actually I did implement such things with suggestions from @sekikn
<https://github.com/sekikn>. Please have a look at:
- the discussion
<https://issues.apache.org/jira/browse/AVRO-2723?focusedCommentId=17054576&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17054576>
- the actual implementation
<https://github.com/anhldbk/avro-fork/blob/dev/lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java#L103-L195>.
I've written several tests against UseInitialValueAsDefault. Some
failed to run due to several reasons
<https://github.com/anhldbk/avro-fork#why-this-fork>.
So I decided to put a partial implementation in this PR and gradually
resolved my issues
<https://issues.apache.org/jira/browse/AVRO-2785?jql=project%20%3D%20AVRO%20AND%20reporter%20in%20(anhldbk)%20ORDER%20BY%20reporter%20ASC%2C%20created%20DESC>
.
Is that ok?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#842 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACCC6R6PJYADMLB6D7JEX3RLZ6L5ANCNFSM4LDXVZVA>
.
|
Yep, I like this point. So to finalize this PR, I'm gonna implement |
@cutting Please response ;) |
Yes, that sounds like a good plan to me. Thanks. |
@cutting Please have a look at my new commits. Travis failed with an unrelated error (in Ruby) |
New public & protected methods need javadoc comments. Also, the new fields should probably be private, not protected. Might the cache be better as WeakHashMap<Class,Object>? I don't see where isFieldInitialized is called. |
- More Java docs - All protected fields are marked as private - Use WeakHashMap instead of HashMap for caching default values
- Rename function `setDefaultValue` into `setDefaultGeneratedValue` to make it clear about the purpose
@cutting Thank you for your thorough comments. I've fixed them. |
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
Outdated
Show resolved
Hide resolved
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
Outdated
Show resolved
Hide resolved
lang/java/avro/src/main/java/org/apache/avro/reflect/ReflectData.java
Outdated
Show resolved
Hide resolved
- `defaultValues` to use WeakHashMap to friendly with GC - more thorough documentations. Thank you @cutting for point me out
@cutting I refactored code according your suggestions. Travis complains an issue which is not related to my PR: Thank you & PTAL. |
Make sure you have checked all steps below.
Jira
Tests
No new tests are needed. I just refactor the code base.
Commits
Documentation