wgtmac commented on code in PR #88:
URL: https://github.com/apache/iceberg-cpp/pull/88#discussion_r2063703993


##########
src/iceberg/file_reader.h:
##########
@@ -0,0 +1,142 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+/// \file iceberg/file_reader.h
+/// Reader interface for file formats like Parquet, Avro and ORC.
+
+#include <functional>
+#include <memory>
+#include <optional>
+#include <variant>
+
+#include "iceberg/arrow_c_data.h"
+#include "iceberg/file_format.h"
+#include "iceberg/result.h"
+#include "iceberg/type_fwd.h"
+
+namespace iceberg {
+
+/// \brief Base reader class to read data from different file formats.
+class ICEBERG_EXPORT Reader {
+ public:
+  virtual ~Reader() = default;
+
+  /// \brief Read next data from file.
+  ///
+  /// \return std::monostate if the reader has no more data, otherwise 
`ArrowArray` or
+  /// `StructLike` depending on the data layout by the reader implementation.
+  using Data =
+      std::variant<std::monostate, ArrowArray, std::reference_wrapper<const 
StructLike>>;
+  virtual Result<Data> Next() = 0;
+
+  enum class DataLayout { kArrowArray, kStructLike };
+
+  /// \brief Get the data layout returned by `Next()` of the reader.
+  virtual DataLayout data_layout() const = 0;
+};
+
+/// \brief Wrapper of `Reader` to always return `StructLike`.
+///
+/// If the data layout of the wrapped reader is `ArrowArray`, the data will be 
converted
+/// to `StructLike`; otherwise, the data will be returned as is without any 
cost.
+class ICEBERG_EXPORT StructLikeReader : public Reader {
+ public:
+  explicit StructLikeReader(std::unique_ptr<Reader> reader);
+
+  /// \brief Always read data into `StructLike` or monostate if no more data.
+  Result<Data> Next() final;
+
+  DataLayout data_layout() const final { return DataLayout::kStructLike; }
+
+ private:
+  std::unique_ptr<Reader> reader_;

Review Comment:
   Because this is just an adapter. If the wrapped reader directly returns 
kStructLike, it does nothing. Otherwise it will try to aggregate them into an 
ArrowArray.



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to