API, Core: Make variant classes serializable - #17260
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
rdblue
commented
Jul 16, 2026
| } | ||
|
|
||
| private Object writeReplace() { | ||
| return new SerializationProxy(this); |
Contributor
Author
There was a problem hiding this comment.
All of the Serialized classes use a serialization proxy so that the serialized form of the variant is used.
rdblue
commented
Jul 16, 2026
| private ByteBuffer buffer = null; | ||
| // binary values are held as a serializable byte array rather than a non-serializable ByteBuffer | ||
| private final byte[] binary; | ||
| private transient ByteBuffer buffer = null; |
Contributor
Author
There was a problem hiding this comment.
The only change needed for primitives was to track binary values using a byte[] instead of the ByteBuffer. This is consistent with how we handle Serializable in other classes that have binary data.
rdblue
commented
Jul 16, 2026
| private final Map<String, VariantValue> shreddedFields = Maps.newHashMap(); | ||
| private final Set<String> removedFields = Sets.newHashSet(); | ||
| private SerializationState serializationState = null; | ||
| private transient SerializationState serializationState = null; |
Contributor
Author
There was a problem hiding this comment.
This is lazily created, so there is no problem making it transient.
stevenzwu
approved these changes
Jul 17, 2026
Contributor
Author
|
Thanks for reviewing, @stevenzwu! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Testing
FieldStatswith all types for #17159 uncovered that variant instances are notSerializable. This makes all the variant classes serializable, so that stats can be serialized in tasks. Stats are not currently serialized in tasks because stats are discarded during planning (they're expensive) but I think it's a good idea to ensure that stats can be serialized.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com