wgtmac commented on code in PR #112: URL: https://github.com/apache/iceberg-cpp/pull/112#discussion_r2173636857
########## src/iceberg/table_scan.h: ########## @@ -0,0 +1,204 @@ +/* + * 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 + +#include <string> +#include <vector> + +#include "iceberg/manifest_entry.h" +#include "iceberg/type_fwd.h" + +namespace iceberg { + +class ICEBERG_EXPORT ScanTask { + public: + virtual ~ScanTask() = default; + + /// \brief The number of bytes that should be read by this scan task. + virtual int64_t size_bytes() const = 0; + + /// \brief The number of files that should be read by this scan task. + virtual int32_t files_count() const = 0; + + /// \brief The number of rows that should be read by this scan task. + virtual int64_t estimated_row_count() const = 0; +}; + +/// \brief Represents a task to scan a portion of a data file. +class ICEBERG_EXPORT FileScanTask : public ScanTask { + public: + FileScanTask(std::shared_ptr<DataFile> file, + std::vector<std::shared_ptr<DataFile>> delete_files, int64_t start, + int64_t length, std::shared_ptr<Expression> residual); + + /// \brief The data file that should be read by this scan task. + const std::shared_ptr<DataFile>& data_file() const; + + /// \brief The delete files that should be read by this scan task. + const std::vector<std::shared_ptr<DataFile>>& delete_files() const; + + /// \brief The byte offset in the data file where the scan should start. + int64_t start() const; + + /// \brief The length in bytes to scan from the start offset. + int64_t length() const; + + /// \brief The residual expression to apply after scanning the data file. + const std::shared_ptr<Expression>& residual() const; + + int64_t size_bytes() const override; + int32_t files_count() const override; + int64_t estimated_row_count() const override; + + private: + std::shared_ptr<DataFile> data_file_; ///< Data file metadata. + std::vector<std::shared_ptr<DataFile>> delete_files_; ///< Delete files metadata. + + int64_t start_; ///< Start byte offset. + int64_t length_; ///< Length in bytes to scan. + + std::shared_ptr<Expression> residual_; ///< Residual expression to apply. +}; + +/// \brief Scan context holding snapshot and scan-specific metadata. +struct TableScanContext { + std::shared_ptr<TableMetadata> table_metadata; ///< Table metadata. + std::shared_ptr<Snapshot> snapshot; ///< Snapshot to scan. + std::shared_ptr<Schema> projected_schema; ///< Projected schema. + std::shared_ptr<Expression> filter; ///< Filter expression to apply. + bool case_sensitive = false; ///< Whether the scan is case-sensitive. + std::unordered_map<std::string, std::string> + options; ///< Additional options for the scan. + std::optional<int64_t> limit; ///< Optional limit on the number of rows to scan. +}; + +/// \brief Builder class for creating TableScan instances. +class ICEBERG_EXPORT TableScanBuilder { + public: + /// \brief Constructs a TableScanBuilder for the given table. + /// \param table The table to scan. + /// \param table_metadata The metadata of the table to scan. + explicit TableScanBuilder(const Table& table, + std::shared_ptr<TableMetadata> table_metadata); + + /// \brief Sets the snapshot ID to scan. + /// \param snapshot_id The ID of the snapshot. + /// \return Reference to the builder. + TableScanBuilder& WithSnapshotId(int64_t snapshot_id); + + /// \brief Selects columns to include in the scan. + /// \param column_names A list of column names. If empty, all columns will be selected. + /// \return Reference to the builder. + TableScanBuilder& WithColumnNames(std::vector<std::string> column_names); + + /// \brief Sets the schema to use for the scan. + /// \param schema The schema to use. + /// \return Reference to the builder. + TableScanBuilder& WithSchema(std::shared_ptr<Schema> schema); + + /// \brief Applies a filter expression to the scan. + /// \param filter Filter expression to use. + /// \return Reference to the builder. + TableScanBuilder& WithFilter(std::shared_ptr<Expression> filter); + + /// \brief Sets whether the scan should be case-sensitive. + /// \param case_sensitive Whether the scan is case-sensitive. + /// /return Reference to the builder. + TableScanBuilder& WithCaseSensitive(bool case_sensitive); + + /// \brief Sets an option for the scan. + /// \param property The name of the option. + /// \param value The value of the option. + /// \return Reference to the builder. + TableScanBuilder& WithOption(std::string property, std::string value); + + /// \brief Sets an optional limit on the number of rows to scan. + /// \param limit Optional limit on the number of rows. + /// \return Reference to the builder. + TableScanBuilder& WithLimit(std::optional<int64_t> limit); + + /// \brief Builds and returns a TableScan instance. + /// \return A Result containing the TableScan or an error. + Result<std::unique_ptr<TableScan>> Build(); + + private: + const Table& table_; ///< Reference to the table to scan. + std::vector<std::string> column_names_; + std::optional<int64_t> snapshot_id_; + TableScanContext context_; ///< Context for the scan. +}; + +/// \brief Represents a configured scan operation on a table. +class ICEBERG_EXPORT TableScan { + public: + virtual ~TableScan() = default; + + /// \brief Constructs a TableScan with the given context and file I/O. + /// \param context Scan context including snapshot, schema, and filter. + /// \param file_io File I/O instance for reading manifests and data files. + TableScan(TableScanContext context, std::shared_ptr<FileIO> file_io); Review Comment: What is the reason that `file_io` is not included in the `context`? ########## src/iceberg/snapshot.h: ########## @@ -222,6 +222,7 @@ struct ICEBERG_EXPORT DataOperation { /// Snapshots are created by table operations. struct ICEBERG_EXPORT Snapshot { static constexpr int64_t kInvalidSnapshotId = -1; + static constexpr int64_t kInitialSequenceNumber = 0; Review Comment: I'm not sure which one is the best place to define this. Attribute like sequence number belongs to both TableMetadata and Snapshot. Perhaps we can define a `iceberg/constants.h` to define those common constants? ########## src/iceberg/table_scan.h: ########## @@ -0,0 +1,204 @@ +/* + * 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 + +#include <string> +#include <vector> + +#include "iceberg/manifest_entry.h" +#include "iceberg/type_fwd.h" + +namespace iceberg { + +class ICEBERG_EXPORT ScanTask { Review Comment: Add a docstring for this class? ########## src/iceberg/table_scan.h: ########## @@ -0,0 +1,204 @@ +/* + * 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 + +#include <string> +#include <vector> + +#include "iceberg/manifest_entry.h" +#include "iceberg/type_fwd.h" + +namespace iceberg { + +class ICEBERG_EXPORT ScanTask { + public: + virtual ~ScanTask() = default; + + /// \brief The number of bytes that should be read by this scan task. + virtual int64_t size_bytes() const = 0; + + /// \brief The number of files that should be read by this scan task. + virtual int32_t files_count() const = 0; + + /// \brief The number of rows that should be read by this scan task. + virtual int64_t estimated_row_count() const = 0; +}; + +/// \brief Represents a task to scan a portion of a data file. +class ICEBERG_EXPORT FileScanTask : public ScanTask { + public: + FileScanTask(std::shared_ptr<DataFile> file, + std::vector<std::shared_ptr<DataFile>> delete_files, int64_t start, + int64_t length, std::shared_ptr<Expression> residual); + + /// \brief The data file that should be read by this scan task. + const std::shared_ptr<DataFile>& data_file() const; + + /// \brief The delete files that should be read by this scan task. + const std::vector<std::shared_ptr<DataFile>>& delete_files() const; + + /// \brief The byte offset in the data file where the scan should start. + int64_t start() const; + + /// \brief The length in bytes to scan from the start offset. + int64_t length() const; + + /// \brief The residual expression to apply after scanning the data file. + const std::shared_ptr<Expression>& residual() const; + + int64_t size_bytes() const override; + int32_t files_count() const override; + int64_t estimated_row_count() const override; + + private: + std::shared_ptr<DataFile> data_file_; ///< Data file metadata. + std::vector<std::shared_ptr<DataFile>> delete_files_; ///< Delete files metadata. + + int64_t start_; ///< Start byte offset. + int64_t length_; ///< Length in bytes to scan. + + std::shared_ptr<Expression> residual_; ///< Residual expression to apply. +}; + +/// \brief Scan context holding snapshot and scan-specific metadata. +struct TableScanContext { + std::shared_ptr<TableMetadata> table_metadata; ///< Table metadata. + std::shared_ptr<Snapshot> snapshot; ///< Snapshot to scan. + std::shared_ptr<Schema> projected_schema; ///< Projected schema. + std::shared_ptr<Expression> filter; ///< Filter expression to apply. + bool case_sensitive = false; ///< Whether the scan is case-sensitive. + std::unordered_map<std::string, std::string> + options; ///< Additional options for the scan. + std::optional<int64_t> limit; ///< Optional limit on the number of rows to scan. +}; + +/// \brief Builder class for creating TableScan instances. +class ICEBERG_EXPORT TableScanBuilder { + public: + /// \brief Constructs a TableScanBuilder for the given table. + /// \param table The table to scan. + /// \param table_metadata The metadata of the table to scan. + explicit TableScanBuilder(const Table& table, Review Comment: Why do we need both `table` and `table_metadata`? ########## src/iceberg/manifest_reader.h: ########## @@ -43,10 +44,27 @@ class ICEBERG_EXPORT ManifestReader { /// \brief Read manifest files from a manifest list file. class ICEBERG_EXPORT ManifestListReader { public: + virtual ~ManifestListReader() = default; virtual Result<std::span<std::unique_ptr<ManifestFile>>> Files() const = 0; private: std::unique_ptr<StructLikeReader> reader_; }; +/// \brief Creates a reader for the manifest list. +/// \param file_path Path to the manifest list file. +/// \return A Result containing the reader or an error. +Result<std::unique_ptr<ManifestListReader>> CreateManifestListReader( + const std::string& file_path) { Review Comment: I think this is not enough. At least we need extra parameters like `table_format_version` and `file_io`. ########## src/iceberg/manifest_reader.h: ########## @@ -34,6 +34,7 @@ namespace iceberg { /// \brief Read manifest entries from a manifest file. class ICEBERG_EXPORT ManifestReader { public: + virtual ~ManifestReader() = default; Review Comment: Why do we need to explicitly define it? ########## src/iceberg/table_scan.h: ########## @@ -0,0 +1,204 @@ +/* + * 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 + +#include <string> +#include <vector> + +#include "iceberg/manifest_entry.h" +#include "iceberg/type_fwd.h" + +namespace iceberg { + +class ICEBERG_EXPORT ScanTask { + public: + virtual ~ScanTask() = default; + + /// \brief The number of bytes that should be read by this scan task. + virtual int64_t size_bytes() const = 0; + + /// \brief The number of files that should be read by this scan task. + virtual int32_t files_count() const = 0; + + /// \brief The number of rows that should be read by this scan task. + virtual int64_t estimated_row_count() const = 0; +}; + +/// \brief Represents a task to scan a portion of a data file. +class ICEBERG_EXPORT FileScanTask : public ScanTask { + public: + FileScanTask(std::shared_ptr<DataFile> file, + std::vector<std::shared_ptr<DataFile>> delete_files, int64_t start, + int64_t length, std::shared_ptr<Expression> residual); + + /// \brief The data file that should be read by this scan task. + const std::shared_ptr<DataFile>& data_file() const; + + /// \brief The delete files that should be read by this scan task. + const std::vector<std::shared_ptr<DataFile>>& delete_files() const; + + /// \brief The byte offset in the data file where the scan should start. + int64_t start() const; + + /// \brief The length in bytes to scan from the start offset. + int64_t length() const; + + /// \brief The residual expression to apply after scanning the data file. + const std::shared_ptr<Expression>& residual() const; + + int64_t size_bytes() const override; + int32_t files_count() const override; + int64_t estimated_row_count() const override; + + private: + std::shared_ptr<DataFile> data_file_; ///< Data file metadata. + std::vector<std::shared_ptr<DataFile>> delete_files_; ///< Delete files metadata. Review Comment: Should this be `DeleteFile`? ########## src/iceberg/table_scan.h: ########## @@ -0,0 +1,204 @@ +/* + * 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 + +#include <string> +#include <vector> + +#include "iceberg/manifest_entry.h" +#include "iceberg/type_fwd.h" + +namespace iceberg { + +class ICEBERG_EXPORT ScanTask { + public: + virtual ~ScanTask() = default; + + /// \brief The number of bytes that should be read by this scan task. + virtual int64_t size_bytes() const = 0; + + /// \brief The number of files that should be read by this scan task. + virtual int32_t files_count() const = 0; + + /// \brief The number of rows that should be read by this scan task. + virtual int64_t estimated_row_count() const = 0; +}; + +/// \brief Represents a task to scan a portion of a data file. +class ICEBERG_EXPORT FileScanTask : public ScanTask { + public: + FileScanTask(std::shared_ptr<DataFile> file, + std::vector<std::shared_ptr<DataFile>> delete_files, int64_t start, + int64_t length, std::shared_ptr<Expression> residual); + + /// \brief The data file that should be read by this scan task. + const std::shared_ptr<DataFile>& data_file() const; + + /// \brief The delete files that should be read by this scan task. + const std::vector<std::shared_ptr<DataFile>>& delete_files() const; + + /// \brief The byte offset in the data file where the scan should start. + int64_t start() const; + + /// \brief The length in bytes to scan from the start offset. + int64_t length() const; + + /// \brief The residual expression to apply after scanning the data file. + const std::shared_ptr<Expression>& residual() const; + + int64_t size_bytes() const override; + int32_t files_count() const override; + int64_t estimated_row_count() const override; + + private: + std::shared_ptr<DataFile> data_file_; ///< Data file metadata. + std::vector<std::shared_ptr<DataFile>> delete_files_; ///< Delete files metadata. + + int64_t start_; ///< Start byte offset. + int64_t length_; ///< Length in bytes to scan. + + std::shared_ptr<Expression> residual_; ///< Residual expression to apply. +}; + +/// \brief Scan context holding snapshot and scan-specific metadata. +struct TableScanContext { + std::shared_ptr<TableMetadata> table_metadata; ///< Table metadata. + std::shared_ptr<Snapshot> snapshot; ///< Snapshot to scan. + std::shared_ptr<Schema> projected_schema; ///< Projected schema. + std::shared_ptr<Expression> filter; ///< Filter expression to apply. + bool case_sensitive = false; ///< Whether the scan is case-sensitive. + std::unordered_map<std::string, std::string> + options; ///< Additional options for the scan. + std::optional<int64_t> limit; ///< Optional limit on the number of rows to scan. +}; + +/// \brief Builder class for creating TableScan instances. +class ICEBERG_EXPORT TableScanBuilder { + public: + /// \brief Constructs a TableScanBuilder for the given table. + /// \param table The table to scan. + /// \param table_metadata The metadata of the table to scan. + explicit TableScanBuilder(const Table& table, + std::shared_ptr<TableMetadata> table_metadata); + + /// \brief Sets the snapshot ID to scan. + /// \param snapshot_id The ID of the snapshot. + /// \return Reference to the builder. + TableScanBuilder& WithSnapshotId(int64_t snapshot_id); + + /// \brief Selects columns to include in the scan. + /// \param column_names A list of column names. If empty, all columns will be selected. + /// \return Reference to the builder. + TableScanBuilder& WithColumnNames(std::vector<std::string> column_names); + + /// \brief Sets the schema to use for the scan. + /// \param schema The schema to use. + /// \return Reference to the builder. + TableScanBuilder& WithSchema(std::shared_ptr<Schema> schema); + + /// \brief Applies a filter expression to the scan. + /// \param filter Filter expression to use. + /// \return Reference to the builder. + TableScanBuilder& WithFilter(std::shared_ptr<Expression> filter); + + /// \brief Sets whether the scan should be case-sensitive. + /// \param case_sensitive Whether the scan is case-sensitive. + /// /return Reference to the builder. + TableScanBuilder& WithCaseSensitive(bool case_sensitive); + + /// \brief Sets an option for the scan. + /// \param property The name of the option. + /// \param value The value of the option. + /// \return Reference to the builder. + TableScanBuilder& WithOption(std::string property, std::string value); + + /// \brief Sets an optional limit on the number of rows to scan. + /// \param limit Optional limit on the number of rows. + /// \return Reference to the builder. + TableScanBuilder& WithLimit(std::optional<int64_t> limit); + + /// \brief Builds and returns a TableScan instance. + /// \return A Result containing the TableScan or an error. + Result<std::unique_ptr<TableScan>> Build(); + + private: + const Table& table_; ///< Reference to the table to scan. + std::vector<std::string> column_names_; Review Comment: Why there is no `std::shared_ptr<Schema>` for `WithSchema`? Same question for filter. ########## src/iceberg/manifest_reader.h: ########## @@ -43,10 +44,27 @@ class ICEBERG_EXPORT ManifestReader { /// \brief Read manifest files from a manifest list file. class ICEBERG_EXPORT ManifestListReader { public: + virtual ~ManifestListReader() = default; virtual Result<std::span<std::unique_ptr<ManifestFile>>> Files() const = 0; private: std::unique_ptr<StructLikeReader> reader_; }; +/// \brief Creates a reader for the manifest list. +/// \param file_path Path to the manifest list file. +/// \return A Result containing the reader or an error. +Result<std::unique_ptr<ManifestListReader>> CreateManifestListReader( + const std::string& file_path) { Review Comment: BTW, should we use `std::string_view` for path? ########## src/iceberg/table_scan.h: ########## @@ -0,0 +1,204 @@ +/* + * 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 + +#include <string> +#include <vector> + +#include "iceberg/manifest_entry.h" +#include "iceberg/type_fwd.h" + +namespace iceberg { + +class ICEBERG_EXPORT ScanTask { + public: + virtual ~ScanTask() = default; + + /// \brief The number of bytes that should be read by this scan task. + virtual int64_t size_bytes() const = 0; + + /// \brief The number of files that should be read by this scan task. + virtual int32_t files_count() const = 0; + + /// \brief The number of rows that should be read by this scan task. + virtual int64_t estimated_row_count() const = 0; +}; + +/// \brief Represents a task to scan a portion of a data file. +class ICEBERG_EXPORT FileScanTask : public ScanTask { + public: + FileScanTask(std::shared_ptr<DataFile> file, + std::vector<std::shared_ptr<DataFile>> delete_files, int64_t start, + int64_t length, std::shared_ptr<Expression> residual); + + /// \brief The data file that should be read by this scan task. + const std::shared_ptr<DataFile>& data_file() const; + + /// \brief The delete files that should be read by this scan task. + const std::vector<std::shared_ptr<DataFile>>& delete_files() const; + + /// \brief The byte offset in the data file where the scan should start. + int64_t start() const; + + /// \brief The length in bytes to scan from the start offset. + int64_t length() const; + + /// \brief The residual expression to apply after scanning the data file. + const std::shared_ptr<Expression>& residual() const; + + int64_t size_bytes() const override; + int32_t files_count() const override; + int64_t estimated_row_count() const override; + + private: + std::shared_ptr<DataFile> data_file_; ///< Data file metadata. + std::vector<std::shared_ptr<DataFile>> delete_files_; ///< Delete files metadata. + + int64_t start_; ///< Start byte offset. + int64_t length_; ///< Length in bytes to scan. + + std::shared_ptr<Expression> residual_; ///< Residual expression to apply. +}; + +/// \brief Scan context holding snapshot and scan-specific metadata. +struct TableScanContext { + std::shared_ptr<TableMetadata> table_metadata; ///< Table metadata. + std::shared_ptr<Snapshot> snapshot; ///< Snapshot to scan. + std::shared_ptr<Schema> projected_schema; ///< Projected schema. + std::shared_ptr<Expression> filter; ///< Filter expression to apply. + bool case_sensitive = false; ///< Whether the scan is case-sensitive. + std::unordered_map<std::string, std::string> + options; ///< Additional options for the scan. + std::optional<int64_t> limit; ///< Optional limit on the number of rows to scan. +}; + +/// \brief Builder class for creating TableScan instances. +class ICEBERG_EXPORT TableScanBuilder { + public: + /// \brief Constructs a TableScanBuilder for the given table. + /// \param table The table to scan. + /// \param table_metadata The metadata of the table to scan. + explicit TableScanBuilder(const Table& table, + std::shared_ptr<TableMetadata> table_metadata); + + /// \brief Sets the snapshot ID to scan. + /// \param snapshot_id The ID of the snapshot. + /// \return Reference to the builder. + TableScanBuilder& WithSnapshotId(int64_t snapshot_id); + + /// \brief Selects columns to include in the scan. + /// \param column_names A list of column names. If empty, all columns will be selected. + /// \return Reference to the builder. + TableScanBuilder& WithColumnNames(std::vector<std::string> column_names); + + /// \brief Sets the schema to use for the scan. + /// \param schema The schema to use. + /// \return Reference to the builder. + TableScanBuilder& WithSchema(std::shared_ptr<Schema> schema); + + /// \brief Applies a filter expression to the scan. + /// \param filter Filter expression to use. + /// \return Reference to the builder. + TableScanBuilder& WithFilter(std::shared_ptr<Expression> filter); + + /// \brief Sets whether the scan should be case-sensitive. + /// \param case_sensitive Whether the scan is case-sensitive. + /// /return Reference to the builder. + TableScanBuilder& WithCaseSensitive(bool case_sensitive); + + /// \brief Sets an option for the scan. + /// \param property The name of the option. + /// \param value The value of the option. + /// \return Reference to the builder. + TableScanBuilder& WithOption(std::string property, std::string value); + + /// \brief Sets an optional limit on the number of rows to scan. + /// \param limit Optional limit on the number of rows. + /// \return Reference to the builder. + TableScanBuilder& WithLimit(std::optional<int64_t> limit); + + /// \brief Builds and returns a TableScan instance. + /// \return A Result containing the TableScan or an error. + Result<std::unique_ptr<TableScan>> Build(); + + private: + const Table& table_; ///< Reference to the table to scan. + std::vector<std::string> column_names_; + std::optional<int64_t> snapshot_id_; + TableScanContext context_; ///< Context for the scan. +}; + +/// \brief Represents a configured scan operation on a table. +class ICEBERG_EXPORT TableScan { + public: + virtual ~TableScan() = default; + + /// \brief Constructs a TableScan with the given context and file I/O. + /// \param context Scan context including snapshot, schema, and filter. + /// \param file_io File I/O instance for reading manifests and data files. + TableScan(TableScanContext context, std::shared_ptr<FileIO> file_io); + + /// \brief Returns the snapshot being scanned. + /// \return A shared pointer to the snapshot. + const std::shared_ptr<Snapshot>& snapshot() const; + + /// \brief Returns the projected schema for the scan. + /// \return A shared pointer to the projected schema. + const std::shared_ptr<Schema>& projection() const; + + /// \brief Returns the scan context. + /// \return A reference to the TableScanContext. + const TableScanContext& context() const; + + /// \brief Returns the file I/O instance used for reading manifests and data files. + /// \return A shared pointer to the FileIO instance. + const std::shared_ptr<FileIO>& io() const; + + /// \brief Plans the scan tasks by resolving manifests and data files. + /// \return A Result containing scan tasks or an error. + virtual Result<std::vector<std::shared_ptr<FileScanTask>>> PlanFiles() const = 0; + + protected: + const TableScanContext context_; + std::shared_ptr<FileIO> file_io_; +}; + +class ICEBERG_EXPORT DataScan : public TableScan { + public: + DataScan(TableScanContext context, std::shared_ptr<FileIO> file_io); + + /// \brief Plans the scan tasks by resolving manifests and data files. + /// \return A Result containing scan tasks or an error. + Result<std::vector<std::shared_ptr<FileScanTask>>> PlanFiles() const override; + + private: + // Use indexed data structures for efficient lookups + struct DeleteFileIndex { Review Comment: Should we just move them to source file since they are private and static? -- 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