YinZheng-Sun commented on code in PR #1068:
URL: https://github.com/apache/iceberg-cpp/pull/1068#discussion_r4695545589
##########
src/iceberg/data/file_scan_task_reader.cc:
##########
@@ -29,23 +29,48 @@
#include "iceberg/data/delete_filter.h"
#include "iceberg/file_reader.h"
#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/partition_spec.h"
#include "iceberg/schema.h"
#include "iceberg/schema_internal.h"
#include "iceberg/table_scan.h"
+#include "iceberg/transform.h"
#include "iceberg/util/macros.h"
namespace iceberg {
namespace {
-ReaderOptions MakeReaderOptions(const FileScanTask& task,
std::shared_ptr<FileIO> io,
- std::shared_ptr<Schema> projection,
- std::shared_ptr<Expression> filter, bool
case_sensitive,
- std::shared_ptr<NameMapping> name_mapping,
- ReaderProperties properties,
- std::optional<int64_t> first_row_id,
- std::optional<int64_t> data_sequence_number) {
+Result<std::unordered_map<int32_t, Literal>> ConstantsOf(const FileScanTask&
task) {
+ const auto& file = *task.data_file();
+ const auto& spec = task.spec();
+ std::unordered_map<int32_t, Literal> id_to_constant;
+ if (!spec) {
+ if (file.partition.num_fields() != 0) {
+ return InvalidArgument("A partition spec is required to read partition
values");
+ }
+ return id_to_constant;
+ }
+ for (size_t i = 0; i < spec->fields().size(); ++i) {
+ const auto& field = spec->fields()[i];
+ if (field.transform() == nullptr) {
+ return InvalidArgument("Missing transform for partition field {}",
+ field.field_id());
+ }
+ if (field.transform()->transform_type() == TransformType::kIdentity) {
+ id_to_constant.emplace(field.source_id(), file.partition.values()[i]);
Review Comment:
Good catch, thanks! Fixed in a83a681. `ConstantsOf()` now validates that
`file.partition.num_fields()` matches `spec->fields().size()` and returns
InvalidArgument with the file path and spec id on mismatch. It also uses
`PartitionValues::ValueAt(i)` (via ICEBERG_ASSIGN_OR_RAISE) instead of raw
indexing, so a malformed partition tuple can no longer cause out-of-bounds
access. Added `RejectsPartitionValuesNotMatchingSpec` to cover this case.
--
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]