-
Notifications
You must be signed in to change notification settings - Fork 91
feat(kv-ir): Add UnstructuredIrDeserializerImpl implementation for unstructured IR deserialization (resolves #2096).
#2227
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
Changes from 8 commits
743d0c6
1616cd7
1a19382
ac369b5
0df70b6
4fd5df9
afbff01
25fad2d
972bae0
5c9c8c5
479987c
8fce488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,17 +2,16 @@ | |
| #define CLP_FFI_IR_STREAM_DESERIALIZER_HPP | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <system_error> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include <nlohmann/json.hpp> | ||
| #include <nlohmann/json_fwd.hpp> | ||
| #include <ystdlib/error_handling/Result.hpp> | ||
|
|
||
| #include "../../ir/types.hpp" | ||
| #include "../../ReaderInterface.hpp" | ||
| #include "../../time_types.hpp" | ||
| #include "../SchemaTree.hpp" | ||
|
|
@@ -23,6 +22,7 @@ | |
| #include "protocol_constants.hpp" | ||
| #include "search/AstEvaluationResult.hpp" | ||
| #include "search/QueryHandlerReq.hpp" | ||
| #include "UnstructuredIrDeserializerImpl.hpp" | ||
| #include "utils.hpp" | ||
|
|
||
| // This include has a circular dependency with the `.inc` file. | ||
|
|
@@ -244,9 +244,7 @@ auto Deserializer<IrUnitHandlerType, QueryHandlerType>::create_generic( | |
| IrUnitHandlerType ir_unit_handler, | ||
| QueryHandlerType query_handler | ||
| ) -> ystdlib::error_handling::Result<Deserializer> { | ||
| [[maybe_unused]] auto const encoding_type{ | ||
| YSTDLIB_ERROR_HANDLING_TRYX(get_encoding_type(reader)) | ||
| }; | ||
| auto const encoding_type{YSTDLIB_ERROR_HANDLING_TRYX(get_encoding_type(reader))}; | ||
| auto const [metadata_type, metadata]{YSTDLIB_ERROR_HANDLING_TRYX(deserialize_preamble(reader))}; | ||
|
|
||
| if (cProtocol::Metadata::EncodingJson != metadata_type) { | ||
|
|
@@ -261,21 +259,40 @@ auto Deserializer<IrUnitHandlerType, QueryHandlerType>::create_generic( | |
| if (metadata_json.end() == version_iter || false == version_iter->is_string()) { | ||
| return std::errc::protocol_error; | ||
| } | ||
| auto const version = version_iter->get_ref<nlohmann::json::string_t&>(); | ||
| if (ffi::ir_stream::IRProtocolErrorCode::Supported | ||
| != ffi::ir_stream::validate_protocol_version(version)) | ||
| auto const version{version_iter->get_ref<nlohmann::json::string_t const&>()}; | ||
| auto const protocol_version_status{ffi::ir_stream::validate_protocol_version(version)}; | ||
| if (ffi::ir_stream::IRProtocolErrorCode::Supported != protocol_version_status | ||
| && ffi::ir_stream::IRProtocolErrorCode::BackwardCompatible != protocol_version_status) | ||
| { | ||
| return std::errc::protocol_not_supported; | ||
| } | ||
|
|
||
| if (metadata_json.contains(cProtocol::Metadata::UserDefinedMetadataKey) | ||
| && false == metadata_json.at(cProtocol::Metadata::UserDefinedMetadataKey).is_object()) | ||
| { | ||
| return std::errc::protocol_not_supported; | ||
| std::unique_ptr<DeserializerImpl> deserializer_impl; | ||
| if (ffi::ir_stream::IRProtocolErrorCode::Supported == protocol_version_status) { | ||
|
jonathan-imanu marked this conversation as resolved.
Outdated
|
||
| if (metadata_json.contains(cProtocol::Metadata::UserDefinedMetadataKey) | ||
| && false == metadata_json.at(cProtocol::Metadata::UserDefinedMetadataKey).is_object()) | ||
| { | ||
| return std::errc::protocol_not_supported; | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the metadata check. It should be supported for both kv-ir and the old IR format. Let's move it outside of this if-else cluster. |
||
| deserializer_impl = std::make_unique<KvIrDeserializerImpl>(); | ||
| } else { | ||
| if (EncodingType::FourByte == encoding_type) { | ||
| deserializer_impl = YSTDLIB_ERROR_HANDLING_TRYX( | ||
| UnstructuredIrDeserializerImpl<ir::four_byte_encoded_variable_t>::create( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to update the docstring to reflect that it forwards |
||
| metadata_json | ||
| ) | ||
| ); | ||
| } else { | ||
| deserializer_impl = YSTDLIB_ERROR_HANDLING_TRYX( | ||
| UnstructuredIrDeserializerImpl<ir::eight_byte_encoded_variable_t>::create( | ||
| metadata_json | ||
| ) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| return Deserializer{ | ||
| std::make_unique<KvIrDeserializerImpl>(), | ||
| std::move(deserializer_impl), | ||
| std::move(ir_unit_handler), | ||
| std::move(metadata_json), | ||
| std::move(query_handler) | ||
|
|
@@ -329,10 +346,13 @@ auto Deserializer<IrUnitHandler, QueryHandlerType>::deserialize_next_ir_unit( | |
| } | ||
|
|
||
| case IrUnitType::SchemaTreeNodeInsertion: { | ||
| std::string key_name; | ||
| std::string key_name_buffer; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this buffer should be made as a member variable of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain
🏁 Script executed: Length of output: 43
The issue captures the proposal to move 🧠 Learnings used |
||
| auto const [is_auto_generated, node_locator]{YSTDLIB_ERROR_HANDLING_TRYX( | ||
| m_deserializer_impl | ||
| ->deserialize_ir_unit_schema_tree_node_insertion(reader, tag, key_name) | ||
| m_deserializer_impl->deserialize_ir_unit_schema_tree_node_insertion( | ||
| reader, | ||
| tag, | ||
| key_name_buffer | ||
| ) | ||
| )}; | ||
| auto& schema_tree_to_insert{ | ||
| is_auto_generated ? m_auto_gen_keys_schema_tree : m_user_gen_keys_schema_tree | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,8 @@ | |
|
|
||
| namespace clp::ffi::ir_stream { | ||
| /** | ||
| * Virtual base class defining methods for deserializing IR units and log events called by | ||
| * `Deserializer`. | ||
| * Virtual base class defining methods for deserializing IR units and log events | ||
| * called by `Deserializer`. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change should be reverted (might be introduced by IDE auto-formatter). |
||
| */ | ||
| class DeserializerImpl { | ||
| public: | ||
|
|
@@ -38,8 +38,8 @@ class DeserializerImpl { | |
| /** | ||
| * Deserializes a UTC offset change IR unit from the given reader. | ||
| * @param reader | ||
| * @return A result containing the deserialized UTC offset on success, or an error code | ||
| * indicating the failure: | ||
| * @return A result containing the deserialized UTC offset on success, or an | ||
| * error code indicating the failure: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert. |
||
| * - Forwards `deserialize_int`'s return values on failure. | ||
| */ | ||
| [[nodiscard]] static auto deserialize_ir_unit_utc_offset_change(ReaderInterface& reader) | ||
|
|
@@ -48,7 +48,8 @@ class DeserializerImpl { | |
| /** | ||
| * Deserializes the type of the next IR unit from the given reader. | ||
| * @param reader | ||
| * @return A result containing a pair on success, or an error code indicating the failure: | ||
| * @return A result containing a pair on success, or an error code indicating | ||
| * the failure: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert. |
||
| * - The pair: | ||
| * - The type of the deserialized IR unit. | ||
| * - The tag of the deserialized IR unit. | ||
|
|
@@ -65,8 +66,8 @@ class DeserializerImpl { | |
| * @param auto_gen_keys_schema_tree | ||
| * @param user_gen_keys_schema_tree | ||
| * @param utc_offset | ||
| * @return A result containing the deserialized KV pair log event on success, or an error code | ||
| * indicating the failure defined by the derived class. | ||
| * @return A result containing the deserialized KV pair log event on success, | ||
| * or an error code indicating the failure defined by the derived class. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert. |
||
| */ | ||
| [[nodiscard]] virtual auto deserialize_ir_unit_kv_pair_log_event( | ||
| ReaderInterface& reader, | ||
|
|
@@ -81,8 +82,10 @@ class DeserializerImpl { | |
| * Deserializes a schema tree node insertion IR unit from the given reader. | ||
| * @param reader | ||
| * @param tag | ||
| * @param key_name Returns the inserted node's key name. | ||
| * @return A result containing a pair on success, or an error code indicating the failure: | ||
| * @param key_name_buffer Returns the inserted node's key name. May be empty | ||
| * if the implementation does not read a key from the stream. | ||
| * @return A result containing a pair on success, or an error code indicating | ||
| * the failure: | ||
|
jonathan-imanu marked this conversation as resolved.
Outdated
|
||
| * - The pair: | ||
| * - Whether the node is for auto-generated keys schema tree. | ||
| * - The locator of the inserted schema tree node. | ||
|
|
@@ -91,7 +94,7 @@ class DeserializerImpl { | |
| [[nodiscard]] virtual auto deserialize_ir_unit_schema_tree_node_insertion( | ||
| ReaderInterface& reader, | ||
| encoded_tag_t tag, | ||
| std::string& key_name | ||
| std::string& key_name_buffer | ||
| ) -> ystdlib::error_handling::Result<std::pair<bool, SchemaTree::NodeLocator>> | ||
| = 0; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,14 @@ enum class IrDeserializationErrorEnum : uint8_t { | |
| IncompleteStream, | ||
| InvalidKeyGroupOrdering, | ||
| InvalidMagicNumber, | ||
| InvalidReferenceTimestampMetadata, | ||
| InvalidReferenceTimestampValue, | ||
| InvalidTag, | ||
| UnsupportedMetadataFormat, | ||
| UnsupportedVersion, | ||
| MissingRequiredSchemaNodes, | ||
| UnknownSchemaTreeNodeType, | ||
| UnknownValueType, | ||
| UnsupportedMetadataFormat, | ||
| UnsupportedVersion, | ||
|
Comment on lines
+19
to
+26
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep existing Lines 19-26 insert new members in the middle of a public Proposed fix enum class IrDeserializationErrorEnum : uint8_t {
DuplicateKey = 1,
- EncodedTextAstDeserializationFailure,
- EndOfStream,
- IncompleteStream,
- InvalidKeyGroupOrdering,
- InvalidMagicNumber,
- InvalidReferenceTimestampMetadata,
- InvalidReferenceTimestampValue,
- InvalidTag,
- MissingRequiredSchemaNodes,
- UnknownSchemaTreeNodeType,
- UnknownValueType,
- UnsupportedMetadataFormat,
- UnsupportedVersion,
+ EncodedTextAstDeserializationFailure = 2,
+ EndOfStream = 3,
+ IncompleteStream = 4,
+ InvalidKeyGroupOrdering = 5,
+ InvalidMagicNumber = 6,
+ InvalidTag = 7,
+ UnknownSchemaTreeNodeType = 8,
+ UnknownValueType = 9,
+ UnsupportedMetadataFormat = 10,
+ UnsupportedVersion = 11,
+ InvalidReferenceTimestampMetadata = 12,
+ InvalidReferenceTimestampValue = 13,
+ MissingRequiredSchemaNodes = 14,
};🤖 Prompt for AI Agents |
||
| }; | ||
|
|
||
| using IrDeserializationError = ystdlib::error_handling::ErrorCode<IrDeserializationErrorEnum>; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.