Skip to content

Commit

Permalink
Merging main
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZhihao-723 committed Nov 24, 2024
1 parent 1efaeed commit 83871a5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 11 deletions.
48 changes: 37 additions & 11 deletions components/core/src/clp/ffi/KeyValuePairLogEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,18 @@ node_type_matches_value_type(SchemaTree::Node::Type type, Value const& value) ->

/**
* Serializes the given node ID value pairs into a `nlohmann::json` object.
* @param schema_tree
* @param node_id_value_pairs
* @param schema_subtree_bitmap
* @return A result containing the serialized JSON object or an error code indicating the failure:
* - std::errc::protocol_error if a value in the log event couldn't be decoded or it couldn't be
* inserted into a JSON object.
* - std::errc::result_out_of_range if a node ID in the log event doesn't exist in the schema tree.
*/
[[nodiscard]] auto serialize_node_id_value_pairs_to_json(
SchemaTree const& schema_tree,
KeyValuePairLogEvent::NodeIdValuePairs const& node_id_value_pairs
KeyValuePairLogEvent::NodeIdValuePairs const& node_id_value_pairs,
vector<bool> const& schema_subtree_bitmap
) -> OUTCOME_V2_NAMESPACE::std_result<nlohmann::json>;

/**
Expand Down Expand Up @@ -425,7 +429,8 @@ auto decode_as_encoded_text_ast(Value const& val) -> std::optional<string> {

auto serialize_node_id_value_pairs_to_json(
SchemaTree const& schema_tree,
KeyValuePairLogEvent::NodeIdValuePairs const& node_id_value_pairs
KeyValuePairLogEvent::NodeIdValuePairs const& node_id_value_pairs,
vector<bool> const& schema_subtree_bitmap
) -> OUTCOME_V2_NAMESPACE::std_result<nlohmann::json> {
if (node_id_value_pairs.empty()) {
return nlohmann::json::object();
Expand All @@ -441,13 +446,6 @@ auto serialize_node_id_value_pairs_to_json(
// vector grows).
std::stack<DfsIterator> dfs_stack;

auto const schema_subtree_bitmap_ret{get_schema_subtree_bitmap(node_id_value_pairs, schema_tree)
};
if (schema_subtree_bitmap_ret.has_error()) {
return schema_subtree_bitmap_ret.error();
}
auto const& schema_subtree_bitmap{schema_subtree_bitmap_ret.value()};

// Traverse the schema tree in DFS order, but only traverse the nodes that are set in
// `schema_subtree_bitmap`.
//
Expand Down Expand Up @@ -563,19 +561,47 @@ auto KeyValuePairLogEvent::create(
};
}

auto KeyValuePairLogEvent::get_auto_generated_schema_subtree_bitmap(
) const -> OUTCOME_V2_NAMESPACE::std_result<std::vector<bool>> {
return get_schema_subtree_bitmap(
m_auto_generated_node_id_value_pairs,
*m_auto_generated_schema_tree
);
}

auto KeyValuePairLogEvent::get_user_generated_schema_subtree_bitmap(
) const -> outcome_v2::std_result<std::vector<bool>> {
return get_schema_subtree_bitmap(
m_user_generated_node_id_value_pairs,
*m_user_generated_schema_tree
);
}

auto KeyValuePairLogEvent::serialize_to_json(
) const -> OUTCOME_V2_NAMESPACE::std_result<std::pair<nlohmann::json, nlohmann::json>> {
auto const auto_generated_schema_subtree_bitmap_result{get_auto_generated_schema_subtree_bitmap(
)};
if (auto_generated_schema_subtree_bitmap_result.has_error()) {
return auto_generated_schema_subtree_bitmap_result.error();
}
auto serialized_auto_generated_kv_pairs_result{serialize_node_id_value_pairs_to_json(
*m_auto_generated_schema_tree,
m_auto_generated_node_id_value_pairs
m_auto_generated_node_id_value_pairs,
auto_generated_schema_subtree_bitmap_result.value()
)};
if (serialized_auto_generated_kv_pairs_result.has_error()) {
return serialized_auto_generated_kv_pairs_result.error();
}

auto const user_generated_schema_subtree_bitmap_result{get_user_generated_schema_subtree_bitmap(
)};
if (user_generated_schema_subtree_bitmap_result.has_error()) {
return user_generated_schema_subtree_bitmap_result.error();
}
auto serialized_user_generated_kv_pairs_result{serialize_node_id_value_pairs_to_json(
*m_user_generated_schema_tree,
m_user_generated_node_id_value_pairs
m_user_generated_node_id_value_pairs,
user_generated_schema_subtree_bitmap_result.value()
)};
if (serialized_user_generated_kv_pairs_result.has_error()) {
return serialized_user_generated_kv_pairs_result.error();
Expand Down
23 changes: 23 additions & 0 deletions components/core/src/clp/ffi/KeyValuePairLogEvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <optional>
#include <unordered_map>
#include <utility>
#include <vector>

#include <json/single_include/nlohmann/json.hpp>
#include <outcome/single-header/outcome.hpp>
Expand Down Expand Up @@ -77,6 +78,28 @@ class KeyValuePairLogEvent {
return m_user_generated_node_id_value_pairs;
}

/**
* @return A result containing a bitmap where every bit corresponds to the ID of a node in the
* auto-generated schema tree, and the set bits correspond to the nodes in the subtree defined
* by all paths from the root node to the nodes in `m_auto_generated_node_id_value_pairs`; or an
* error code indicating a failure:
* - std::errc::result_out_of_range if a node ID in `m_auto_generated_node_id_value_pairs`
* doesn't exist in the schema tree.
*/
[[nodiscard]] auto get_auto_generated_schema_subtree_bitmap(
) const -> OUTCOME_V2_NAMESPACE::std_result<std::vector<bool>>;

/**
* @return A result containing a bitmap where every bit corresponds to the ID of a node in the
* user-generated schema tree, and the set bits correspond to the nodes in the subtree defined
* by all paths from the root node to the nodes in `m_user_generated_node_id_value_pairs`; or an
* error code indicating a failure:
* - std::errc::result_out_of_range if a node ID in `m_user_generated_node_id_value_pairs`
* doesn't exist in the schema tree.
*/
[[nodiscard]] auto get_user_generated_schema_subtree_bitmap(
) const -> OUTCOME_V2_NAMESPACE::std_result<std::vector<bool>>;

[[nodiscard]] auto get_utc_offset() const -> UtcOffset { return m_utc_offset; }

/**
Expand Down

0 comments on commit 83871a5

Please sign in to comment.