WZhuo commented on code in PR #1066:
URL: https://github.com/apache/iceberg-cpp/pull/1066#discussion_r4408414231


##########
src/iceberg/inspect/metadata_scan_task_reader.cc:
##########
@@ -0,0 +1,64 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "iceberg/inspect/metadata_scan_task_reader.h"
+
+#include <memory>
+#include <utility>
+
+#include "iceberg/inspect/history_table.h"
+#include "iceberg/inspect/metadata_scan_task.h"
+#include "iceberg/inspect/metadata_table.h"
+#include "iceberg/inspect/snapshots_table.h"
+#include "iceberg/util/checked_cast.h"
+#include "iceberg/util/macros.h"
+
+namespace iceberg {
+
+MetadataScanTaskReader::MetadataScanTaskReader(Options options)
+    : options_(std::move(options)) {}
+
+MetadataScanTaskReader::~MetadataScanTaskReader() = default;
+
+Result<std::unique_ptr<MetadataScanTaskReader>> MetadataScanTaskReader::Make(
+    Options options) {
+  ICEBERG_PRECHECK(options.batch_size > 0, "batch size must be positive");
+  return std::unique_ptr<MetadataScanTaskReader>(
+      new MetadataScanTaskReader(std::move(options)));
+}
+
+Result<ArrowArrayStream> MetadataScanTaskReader::Open(
+    const MetadataScanTask& task) const {
+  switch (task.task_kind()) {
+    case MetadataScanTask::TaskKind::kStatic: {
+      const auto& static_task = internal::checked_cast<const 
StaticMetadataTask&>(task);

Review Comment:
   Could we give `MetadataScanTask` a virtual `Open(ReadOptions) const` 
interface and move row production into concrete `SnapshotsScanTask` and 
`HistoryScanTask` implementations? Each task could retain its metadata and 
projected schema, while `ReadOptions` would contain execution settings such as 
batch size.
   
   That would eliminate the centralized task/table-kind dispatch and downcast 
here, as well as the `friend class MetadataScanTaskReader` declaration and 
private static `ReadRows()` method required in each metadata table. Adding a 
new task implementation would no longer require updating this reader.
   
   With that interface, could we remove `MetadataScanTaskReader` altogether 
rather than keep it as a thin forwarding wrapper? Callers could open planned 
tasks directly with `task->Open({.batch_size = 4096})`, and 
`MetadataScan::ToArrowArrayStream()` could open and concatenate them. Each 
`Open()` call should still create independent read state, with the returned 
stream retaining everything it needs to outlive the task.



-- 
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]

Reply via email to