Copilot commented on code in PR #801:
URL: https://github.com/apache/iceberg-cpp/pull/801#discussion_r3689205488
##########
src/iceberg/inspect/snapshots_table.cc:
##########
@@ -19,21 +19,133 @@
#include "iceberg/inspect/snapshots_table.h"
+#include <chrono>
+#include <cstddef>
#include <memory>
+#include <optional>
#include <utility>
#include <vector>
+#include <nanoarrow/nanoarrow.h>
+
+#include "iceberg/arrow/nanoarrow_status_internal.h"
+#include "iceberg/arrow_c_data_util_internal.h"
+#include "iceberg/arrow_row_builder_internal.h"
#include "iceberg/schema.h"
#include "iceberg/schema_field.h"
+#include "iceberg/schema_internal.h"
+#include "iceberg/snapshot.h"
#include "iceberg/table.h"
-#include "iceberg/table_identifier.h"
#include "iceberg/type.h"
+#include "iceberg/util/macros.h"
namespace iceberg {
namespace {
-std::shared_ptr<Schema> MakeSnapshotsTableSchema() {
- return std::make_shared<Schema>(std::vector<SchemaField>{
+Status AppendSnapshot(ArrowRowBuilder& builder, const Snapshot& snapshot) {
+ ICEBERG_RETURN_UNEXPECTED(
+ AppendInt(builder.column(0),
std::chrono::duration_cast<std::chrono::microseconds>(
+
snapshot.timestamp_ms.time_since_epoch())
+ .count()));
+ ICEBERG_RETURN_UNEXPECTED(AppendInt(builder.column(1),
snapshot.snapshot_id));
+
+ if (snapshot.parent_snapshot_id.has_value()) {
+ ICEBERG_RETURN_UNEXPECTED(AppendInt(builder.column(2),
*snapshot.parent_snapshot_id));
+ } else {
+ ICEBERG_RETURN_UNEXPECTED(AppendNull(builder.column(2)));
+ }
+
+ auto operation = snapshot.Operation();
+ if (operation.has_value()) {
+ ICEBERG_RETURN_UNEXPECTED(AppendString(builder.column(3), *operation));
+ } else {
+ ICEBERG_RETURN_UNEXPECTED(AppendNull(builder.column(3)));
+ }
+
+ ICEBERG_RETURN_UNEXPECTED(AppendString(builder.column(4),
snapshot.manifest_list));
+
+ auto summary = snapshot.summary;
+ summary.erase(SnapshotSummaryFields::kOperation);
+ if (summary.empty()) {
+ ICEBERG_RETURN_UNEXPECTED(AppendNull(builder.column(5)));
+ } else {
+ ICEBERG_RETURN_UNEXPECTED(AppendStringMap(builder.column(5), summary));
+ }
+
+ return builder.FinishRow();
+}
+
+class SnapshotsTableStream {
+ public:
+ static Result<std::unique_ptr<SnapshotsTableStream>> Make(
+ std::shared_ptr<Table> table, const iceberg::Schema& schema) {
+ ArrowSchema arrow_schema{};
+ ICEBERG_RETURN_UNEXPECTED(ToArrowSchema(schema, &arrow_schema));
+ return std::unique_ptr<SnapshotsTableStream>(
+ new SnapshotsTableStream(std::move(table), std::move(arrow_schema)));
+ }
+
+ ~SnapshotsTableStream() { std::ignore = Close(); }
Review Comment:
`std::ignore` is defined in `<tuple>`, but this file doesn't include
`<tuple>`, which can cause a compile error. Either add `#include <tuple>` or
replace this with a simpler pattern (e.g., `(void)Close();`) that doesn't
require `std::ignore`.
##########
src/iceberg/inspect/snapshots_table.cc:
##########
@@ -19,21 +19,133 @@
#include "iceberg/inspect/snapshots_table.h"
+#include <chrono>
+#include <cstddef>
#include <memory>
+#include <optional>
#include <utility>
#include <vector>
+#include <nanoarrow/nanoarrow.h>
+
+#include "iceberg/arrow/nanoarrow_status_internal.h"
+#include "iceberg/arrow_c_data_util_internal.h"
+#include "iceberg/arrow_row_builder_internal.h"
#include "iceberg/schema.h"
#include "iceberg/schema_field.h"
+#include "iceberg/schema_internal.h"
+#include "iceberg/snapshot.h"
#include "iceberg/table.h"
-#include "iceberg/table_identifier.h"
#include "iceberg/type.h"
+#include "iceberg/util/macros.h"
namespace iceberg {
namespace {
-std::shared_ptr<Schema> MakeSnapshotsTableSchema() {
- return std::make_shared<Schema>(std::vector<SchemaField>{
+Status AppendSnapshot(ArrowRowBuilder& builder, const Snapshot& snapshot) {
+ ICEBERG_RETURN_UNEXPECTED(
+ AppendInt(builder.column(0),
std::chrono::duration_cast<std::chrono::microseconds>(
+
snapshot.timestamp_ms.time_since_epoch())
+ .count()));
+ ICEBERG_RETURN_UNEXPECTED(AppendInt(builder.column(1),
snapshot.snapshot_id));
+
+ if (snapshot.parent_snapshot_id.has_value()) {
+ ICEBERG_RETURN_UNEXPECTED(AppendInt(builder.column(2),
*snapshot.parent_snapshot_id));
+ } else {
+ ICEBERG_RETURN_UNEXPECTED(AppendNull(builder.column(2)));
+ }
+
+ auto operation = snapshot.Operation();
+ if (operation.has_value()) {
+ ICEBERG_RETURN_UNEXPECTED(AppendString(builder.column(3), *operation));
+ } else {
+ ICEBERG_RETURN_UNEXPECTED(AppendNull(builder.column(3)));
+ }
+
+ ICEBERG_RETURN_UNEXPECTED(AppendString(builder.column(4),
snapshot.manifest_list));
+
+ auto summary = snapshot.summary;
+ summary.erase(SnapshotSummaryFields::kOperation);
+ if (summary.empty()) {
+ ICEBERG_RETURN_UNEXPECTED(AppendNull(builder.column(5)));
+ } else {
+ ICEBERG_RETURN_UNEXPECTED(AppendStringMap(builder.column(5), summary));
+ }
+
+ return builder.FinishRow();
+}
+
+class SnapshotsTableStream {
+ public:
+ static Result<std::unique_ptr<SnapshotsTableStream>> Make(
+ std::shared_ptr<Table> table, const iceberg::Schema& schema) {
+ ArrowSchema arrow_schema{};
+ ICEBERG_RETURN_UNEXPECTED(ToArrowSchema(schema, &arrow_schema));
+ return std::unique_ptr<SnapshotsTableStream>(
+ new SnapshotsTableStream(std::move(table), std::move(arrow_schema)));
+ }
+
+ ~SnapshotsTableStream() { std::ignore = Close(); }
+
+ Status Close() {
+ table_.reset();
+ if (arrow_schema_.release != nullptr) {
+ ArrowSchemaRelease(&arrow_schema_);
+ }
+ return {};
+ }
+
+ Result<std::optional<ArrowArray>> Next() {
+ const auto& snapshots = table_->snapshots();
+ if (next_snapshot_ == snapshots.size()) {
+ return std::nullopt;
+ }
Review Comment:
`Close()` resets `table_`, but `Next()` unconditionally dereferences
`table_`. If `Next()` is called after the stream is closed (even accidentally),
this will crash. Add a guard at the start of `Next()` similar to `Schema()`
(e.g., return `InvalidArgument(...)` when `table_` is null / stream is closed).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]