Skip to content

Commit 9a10775

Browse files
authored
Improve StageResult printout (#2760)
#### Reference Issues/PRs <!--Example: Fixes #1234. See also #3456.--> #### What does this implement or fix? Improve the readability of `StageResult` along with atom keys' printout New `StageResult` printout example: `StageResult(staged_segments=[Key(type=b, id='sym', version_id=0, content_hash=0xac454fbcb62cd989, creation_ts=1763562571272342532, start_index=1735689600000000000, end_index=1735776000000000001), Key(type=b, id='sym', version_id=0, content_hash=0x14e310dcc399815e, creation_ts=1763562571272634201, start_index=1735862400000000000, end_index=1735862400000000001)])` New key printout example: `Key(type=b, id='sym', version_id=0, content_hash=0xac454fbcb62cd989, creation_ts=1763562571272342532, start_index=1735689600000000000, end_index=1735776000000000001)` Docstring for the class has been added to the docs website as well. #### Any other comments? #### Checklist <details> <summary> Checklist for code changes... </summary> - [ ] Have you updated the relevant docstrings, documentation and copyright notice? - [ ] Is this contribution tested against [all ArcticDB's features](../docs/mkdocs/docs/technical/contributing.md)? - [ ] Do all exceptions introduced raise appropriate [error messages](https://docs.arcticdb.io/error_messages/)? - [ ] Are API changes highlighted in the PR description? - [ ] Is the PR labelled as enhancement or bug so it appears in autogenerated release notes? </details> <!-- Thanks for contributing a Pull Request to ArcticDB! Please ensure you have taken a look at: - ArcticDB's Code of Conduct: https://github.com/man-group/ArcticDB/blob/master/CODE_OF_CONDUCT.md - ArcticDB's Contribution Licensing: https://github.com/man-group/ArcticDB/blob/master/docs/mkdocs/docs/technical/contributing.md#contribution-licensing -->
1 parent a03148a commit 9a10775

File tree

7 files changed

+53
-3
lines changed

7 files changed

+53
-3
lines changed

cpp/arcticdb/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ set(arcticdb_srcs
228228
entity/ref_key.hpp
229229
entity/serialized_key.hpp
230230
entity/stage_result.hpp
231+
entity/stage_result.cpp
231232
entity/type_conversion.hpp
232233
entity/types.hpp
233234
entity/type_utils.hpp

cpp/arcticdb/entity/atom_key.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ class AtomKeyImpl {
116116
return {str_};
117117
}
118118

119+
std::string view_human() const;
120+
119121
private:
120122
StreamId id_;
121123
VersionId version_id_ = 0;
@@ -328,4 +330,8 @@ struct hash<arcticdb::entity::AtomKeyImpl> {
328330
namespace arcticdb::entity {
329331
// This needs to be defined AFTER the formatter for AtomKeyImpl
330332
inline void AtomKeyImpl::set_string() const { str_ = fmt::format("{}", *this); }
333+
334+
inline std::string AtomKeyImpl::view_human() const {
335+
return fmt::format("{}", formattable<AtomKeyImpl, DisplayAtomKeyFormat>(*this));
336+
}
331337
} // namespace arcticdb::entity

cpp/arcticdb/entity/key.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ struct DefaultAtomKeyFormat {
2222
static constexpr char format[] = "{}:{}:{:d}:0x{:x}@{:d}[{},{}]";
2323
};
2424

25+
struct DisplayAtomKeyFormat {
26+
static constexpr char format[] = "Key(type={}, id='{}', version_id={:d}, content_hash=0x{:x}, creation_ts={:d}, "
27+
"start_index={}, end_index={})";
28+
};
29+
2530
template<class T, class FormattingTag = DefaultAtomKeyFormat>
2631
struct FormattableRef {
2732
const T& ref;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <arcticdb/entity/stage_result.hpp>
2+
3+
namespace arcticdb {
4+
std::string StageResult::view() const { return fmt::format("{}", *this); }
5+
} // namespace arcticdb

cpp/arcticdb/entity/stage_result.hpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,33 @@
1010

1111
#include <arcticdb/entity/atom_key.hpp>
1212
#include <vector>
13+
#include <ranges>
14+
#include <fmt/format.h>
15+
#include <fmt/ranges.h>
1316

1417
namespace arcticdb {
1518
struct StageResult {
1619
explicit StageResult(std::vector<entity::AtomKey> staged_segments) : staged_segments(std::move(staged_segments)) {}
1720

1821
std::vector<entity::AtomKey> staged_segments;
22+
23+
std::string view() const;
24+
};
25+
} // namespace arcticdb
26+
27+
namespace fmt {
28+
template<>
29+
struct formatter<arcticdb::StageResult> {
30+
template<typename ParseContext>
31+
constexpr auto parse(ParseContext& ctx) {
32+
return ctx.begin();
33+
}
34+
35+
template<typename FormatContext>
36+
auto format(const arcticdb::StageResult& stage_result, FormatContext& ctx) const {
37+
auto transform_view =
38+
stage_result.staged_segments | std::views::transform([](const auto& key) { return key.view_human(); });
39+
return fmt::format_to(ctx.out(), "StageResult(staged_segments=[{}])", fmt::join(transform_view, ", "));
40+
}
1941
};
20-
} // namespace arcticdb
42+
} // namespace fmt

cpp/arcticdb/version/python_bindings.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ void register_bindings(py::module& version, py::exception<arcticdb::ArcticExcept
157157
.def_property_readonly("type", [](const AtomKey& self) { return self.type(); })
158158
.def(pybind11::self == pybind11::self)
159159
.def(pybind11::self != pybind11::self)
160-
.def("__repr__", &AtomKey::view)
160+
.def("__repr__", &AtomKey::view_human)
161161
.def(py::self < py::self)
162162
.def(py::pickle(
163163
[](const AtomKey& key) {
@@ -375,9 +375,19 @@ void register_bindings(py::module& version, py::exception<arcticdb::ArcticExcept
375375
.def_property_readonly("creation_ts", &DescriptorItem::creation_ts)
376376
.def_property_readonly("timeseries_descriptor", &DescriptorItem::timeseries_descriptor);
377377

378-
py::class_<StageResult>(version, "StageResult")
378+
py::class_<StageResult>(version, "StageResult", R"pbdoc(
379+
Result returned by the stage method containing information about staged segments.
380+
381+
StageResult objects can be passed to finalization methods to specify which staged data to finalize.
382+
This enables selective finalization of staged data when multiple stage operations have been performed.
383+
384+
Attributes
385+
----------
386+
staged_segments : List[AtomKey]
387+
)pbdoc")
379388
.def(py::init([]() { return StageResult({}); }))
380389
.def_property_readonly("staged_segments", [](const StageResult& self) { return self.staged_segments; })
390+
.def("__repr__", &StageResult::view)
381391
.def(py::pickle(
382392
[](const StageResult& s) {
383393
constexpr int serialization_version = 0;

docs/mkdocs/docs/api/library_types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@
2222

2323
::: arcticdb.WriteMetadataPayload
2424

25+
::: arcticdb_ext.version_store.StageResult

0 commit comments

Comments
 (0)