-
Notifications
You must be signed in to change notification settings - Fork 1.4k
refactor: Implement one step type registration and serialization/deserialization for OpaqueCustomType #15843
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
base: main
Are you sure you want to change the base?
refactor: Implement one step type registration and serialization/deserialization for OpaqueCustomType #15843
Conversation
✅ Deploy Preview for meta-velox canceled.
|
|
@AshishCbMisra has exported this pull request. If you are a Meta employee, you can view the originating Diff in D89686612. |
c60f365 to
aeb814f
Compare
…rialization for OpaqueCustomType (facebookincubator#15843) Summary: ## Background. - Today, a CustomType (inner type) may be wrapped by an OpaqueType (outer type), forming a OpaqueCustomType. - When an OpaqueCustomType is defined, it needs to be registered in two place. - Custom Type Registry - a mapping from type name to an instance of CustomTypeFactory that provides an instance of the type - OpaqueSerdeRegistry - a mapping from type name to functions that serialize and deserialize opaque type values - Today, this requires two separate calls to the API. These separate calls are inconvenient and error prone. ## Implementation - OpaqueCustomTypes.h - This PR changes the OpaqueCustomTypeRegister::registerType() function to accept optional serialization/deserialization functions, thus eliminating the need for a separate API call. - By keep the function arguments optional, it provides backward compatibility with existing code. ## Testing Changes - OpaqueCustomTypesTest.cpp - Implements unit-tests that ensure that serialization/deserialization functions can be provided in the registerType function optionally. - Unit-tests ensure that serialization/deserialization functions can be provided utmost once. Differential Revision: D89686612
aeb814f to
1011baf
Compare
…rialization for OpaqueCustomType (facebookincubator#15843) Summary: ## Background. - Today, a CustomType (inner type) may be wrapped by an OpaqueType (outer type), forming a OpaqueCustomType. - When an OpaqueCustomType is defined, it needs to be registered in two place. - Custom Type Registry - a mapping from type name to an instance of CustomTypeFactory that provides an instance of the type - OpaqueSerdeRegistry - a mapping from type name to functions that serialize and deserialize opaque type values - Today, this requires two separate calls to the API. These separate calls are inconvenient and error prone. ## Implementation - OpaqueCustomTypes.h - This PR changes the OpaqueCustomTypeRegister::registerType() function to accept optional serialization/deserialization functions, thus eliminating the need for a separate API call. - By keep the function arguments optional, it provides backward compatibility with existing code. ## Testing Changes - OpaqueCustomTypesTest.cpp - Implements unit-tests that ensure that serialization/deserialization functions can be provided in the registerType function optionally. - Unit-tests ensure that serialization/deserialization functions can be provided utmost once. Differential Revision: D89686612
…rialization for OpaqueCustomType (facebookincubator#15843) Summary: ## Background. - Today, a CustomType (inner type) may be wrapped by an OpaqueType (outer type), forming a OpaqueCustomType. - When an OpaqueCustomType is defined, it needs to be registered in two place. - Custom Type Registry - a mapping from type name to an instance of CustomTypeFactory that provides an instance of the type - OpaqueSerdeRegistry - a mapping from type name to functions that serialize and deserialize opaque type values - Today, this requires two separate calls to the API. These separate calls are inconvenient and error prone. ## Implementation - OpaqueCustomTypes.h - This PR changes the OpaqueCustomTypeRegister::registerType() function to accept optional serialization/deserialization functions, thus eliminating the need for a separate API call. - By keep the function arguments optional, it provides backward compatibility with existing code. ## Testing Changes - OpaqueCustomTypesTest.cpp - Implements unit-tests that ensure that serialization/deserialization functions can be provided in the registerType function optionally. - Unit-tests ensure that serialization/deserialization functions can be provided utmost once. Differential Revision: D89686612
a0cacd4 to
14f2c87
Compare
14f2c87 to
a56cb95
Compare
| } | ||
| return false; | ||
| } | ||
| template <typename T, const char* customTypeName> |
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.
add empty line between methods
| obj["name"] = "Type"; | ||
| obj["type"] = TypeTraits<TypeKind::OPAQUE>::name; | ||
| obj["opaque"] = customTypeName; |
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.
Why not just
obj["name"] = "Type";
obj["type"] = customTypeName;
?
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.
Couple of reasons:
- It is the OpaqueCustom type. The representation should be as such: Opaque outer type, embedding the custom inner type.
- It breaks backward compatibility. A server running one velox version would break when sending serialized type to another running a previous version.
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 the OpaqueCustom type. The representation should be as such: Opaque outer type, embedding the custom inner type.
Not really. OpaqueType here is just an implementation detail of the custom type. It doesn't / shouldn't place a restriction on how custom type chooses to serialize itself.
It breaks backward compatibility. A server running one velox version would break when sending serialized type to another running a previous version.
There is no such guarantee in Velox to begin with. Let's discuss offline if this needs to be added as it would be non-trivial undertaking.
| auto deserializedType = Type::create(serializedCustomType); | ||
|
|
||
| // TODO: Ideally this should be EXPECT_EQ() but it doesn't work | ||
| // because Type::create() currently does not return the singleton instance. |
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 will work if you just fix 'serialize' method like I suggested.
…rialization for OpaqueCustomType (facebookincubator#15843) Summary: ## Background. - Today, a CustomType (inner type) may be wrapped by an OpaqueType (outer type), forming a OpaqueCustomType. - When an OpaqueCustomType is defined, it needs to be registered in two place. - Custom Type Registry - a mapping from type name to an instance of CustomTypeFactory that provides an instance of the type - OpaqueSerdeRegistry - a mapping from type name to functions that serialize and deserialize opaque type values - Today, this requires two separate calls to the API. These separate calls are inconvenient and error prone. ## Implementation - OpaqueCustomTypes.h - This PR changes the OpaqueCustomTypeRegister::registerType() function to accept optional serialization/deserialization functions, thus eliminating the need for a separate API call. - By keep the function arguments optional, it provides backward compatibility with existing code. - Implemented the VeloxType::serialize() function - Cleared SerializationRegistry of the serialization/deserialization functions provided in the registerType() function. - Types.cpp - Implemented OpaqueType::clearSerializationRegistry() method. ## Testing Changes - OpaqueCustomTypesTest.cpp - Implements unit-tests that ensure that value serialization/deserialization functions can be provided in the registerType function optionally. - Implements checking for type-serialization/deserialization. - TypesTest.cpp Differential Revision: D89686612
a56cb95 to
12d2762
Compare
…rialization for OpaqueCustomType (facebookincubator#15843) Summary: ## Background. - Today, a CustomType (inner type) may be wrapped by an OpaqueType (outer type), forming a OpaqueCustomType. - When an OpaqueCustomType is defined, it needs to be registered in two place. - Custom Type Registry - a mapping from type name to an instance of CustomTypeFactory that provides an instance of the type - OpaqueSerdeRegistry - a mapping from type name to functions that serialize and deserialize opaque type values - Today, this requires two separate calls to the API. These separate calls are inconvenient and error prone. ## Implementation - OpaqueCustomTypes.h - This PR changes the OpaqueCustomTypeRegister::registerType() function to accept optional serialization/deserialization functions, thus eliminating the need for a separate API call. - By keep the function arguments optional, it provides backward compatibility with existing code. - Implemented the VeloxType::serialize() function - Cleared SerializationRegistry of the serialization/deserialization functions provided in the registerType() function. - Types.cpp - Implemented OpaqueType::clearSerializationRegistry() method. ## Testing Changes - OpaqueCustomTypesTest.cpp - Implements unit-tests that ensure that value serialization/deserialization functions can be provided in the registerType function optionally. - Implements checking for type-serialization/deserialization. - TypesTest.cpp Differential Revision: D89686612
12d2762 to
1d8ef69
Compare
| auto& registry = OpaqueSerdeRegistry::get(); | ||
| auto it = registry.mapping.find(opaqueType->typeIndex_); | ||
| if (it != registry.mapping.end()) { | ||
| registry.mapping.erase(opaqueType->typeIndex_); |
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.
perhaps, use the 'it' to erase (no need to lookup the value again)
Summary:
Background.
Implementation
Testing Changes
Differential Revision: D89686612