-
Notifications
You must be signed in to change notification settings - Fork 887
JAVA-721: Allow user to register custom type codecs (2.2 branch). #387
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
Conversation
80e2490 to
032fb3a
Compare
pom.xml
Outdated
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.
Any reason why we couldn't upgrade to an even newer version of Guava (i.e. 18) or are there compatibility issues with other libraries?
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.
I haven't tried, but there is no compatibility issues that I am aware of.
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.
Will bump to 18.0; feels like it's now or never.
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.
👍 my only worry is that this can bring compatibility issues for users, but I think this is acceptable given this is a major release, and that guava is mostly backwards compatible (and in the places its not it should be easy to work around).
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.
Would it be more advisable to recommend calling registerDefaults() first then register(myCodec...) so any custom registered codecs take precedence over the default ones? Or will we not expect it to be normal to override default codecs?
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.
Nevermind this. It looks like registerDefaults was removed as this is now done as part of initialization of codec registry. Documentation should be updated to reflect that.
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.
You're right, I need to update the docs that are a bit outdated.
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.
Let's introduce a builder for this class, like for Policies. This will avoid backward-compatibility issues with the constructors.
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.
Ha, I actually avoided the builder pattern on purpose, because codec registry instances are mutable. But note that the class is final, and users are not meant to mess with it (they can play with TypeCodecs now, but that's all).
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.
This felt kind of weird because i'm changing my CodecRegistry after creating the Cluster, but it seems necessary because we need the ProtocolVersion among other things in order to properly use Tuples. I noticed that the same needs to be done for UDTs (like TypeCodecUDTIntegrationTest)
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.
Yes :( there is a chicken-and-egg problem here, but I don't see any better way.
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.
Although, I changed the constructor to take a TupleCodec as its only argument; at least I think that the instantiation of TimeZonePreservingDateTimeCodec is a bit less convoluted this way.
|
Pushed a few changes to fix some inconsistencies in behavior between this branch and 2.2. I've documented my commits with details of what I changed. Also added some additional validation based on some of these changes. If I did anything incorrect or some of these inconsistencies are intentional feel free to back out. |
|
It looks like there may be a bug when determining what codec to use in Uitls.appendValue (used by QueryBuilder). These two tests test pass most of the same, but sometimes they fail because it appears that they pick up the wrong LongCodec (TimeCodec instead of CounterCodec). With the changes in CodecRegistry to use Cache.asMap() (instead of the CopyOnWriteArrayList) the ordering of codecs is not predictable, so at times it'll choose TimeCodec and other times not, although previously this would have been a problem if CounterCodec was registered first. It looks like this was already known as there is a comment in Utils.isForceAppendToQueryString that is a TODO but thought I'd bring up just in case :) |
features/custom_codecs/README.md
Outdated
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.
CodecRegistryis not meant to be subclassed by clients
So should we make it final?
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.
It is final already.
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.
protocolVersion doesn't seem to be used anywhere.
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.
Indeed. I added that argument on purpose in anticipation of future use, and to be consistent with other methods in this class. But I'm fine if you prefer to remove it.
204a2d7 to
f12fa18
Compare
README file:
https://github.com/datastax/java-driver/blob/java721-2.2/features/custom_codecs/README.md
Upgrade Guide:
https://github.com/datastax/java-driver/blob/java721-2.2/upgrade_guide/README.md