Skip to content

Commit a95f8eb

Browse files
committed
fix(manifest): align bucket pruning and address reader review
1 parent ed64b51 commit a95f8eb

11 files changed

Lines changed: 316 additions & 316 deletions

‎src/paimon/core/manifest/manifest_file.cpp‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Result<std::unique_ptr<ManifestFile>> ManifestFile::Create(
102102

103103
Status ManifestFile::ReadBucketEntries(const std::string& file_name, int32_t bucket,
104104
const std::optional<int32_t>& expected_total_buckets,
105-
std::optional<int64_t> file_size,
105+
std::optional<int64_t> file_size,
106106
std::vector<ManifestEntry>* entries) const {
107107
// Readers without precise bitmap selection still filter aligned Arrow columns
108108
// before constructing ManifestEntry and DataFileMeta objects.
@@ -115,7 +115,7 @@ Status ManifestFile::ReadBucketEntries(const std::string& file_name, int32_t buc
115115
row.SetRowId(i);
116116
PAIMON_RETURN_NOT_OK(
117117
ManifestEntrySerializer::ValidateVersion(row.GetInt(kVersionFieldIndex)));
118-
// Different or unknown bucket counts must reach the compatibility checks.
118+
// Different or unknown bucket counts must reach per-entry bucket filtering.
119119
const bool historical_layout =
120120
expected_total_buckets &&
121121
(row.IsNullAt(kBucketFieldIndex) || row.IsNullAt(kTotalBucketsFieldIndex) ||
@@ -144,28 +144,27 @@ Status ManifestFile::PrepareBucketRead(int32_t bucket,
144144
arrow::ImportSchema(c_schema.get()));
145145
const auto& target_type = serializer_->GetDataType();
146146
const std::string& bucket_name = target_type->field(kBucketFieldIndex)->name();
147-
std::shared_ptr<Predicate> selector = PredicateBuilder::Equal(
148-
file_schema->GetFieldIndex(bucket_name), bucket_name, FieldType::INT, Literal(bucket));
147+
std::shared_ptr<Predicate> selector =
148+
PredicateBuilder::Equal(kBucketFieldIndex, bucket_name, FieldType::INT, Literal(bucket));
149149
if (expected_total_buckets) {
150150
const std::string& total_name = target_type->field(kTotalBucketsFieldIndex)->name();
151-
const int32_t total_index = file_schema->GetFieldIndex(total_name);
152151
PAIMON_ASSIGN_OR_RAISE(
153152
selector,
154153
PredicateBuilder::Or(
155-
{selector, PredicateBuilder::IsNull(total_index, total_name, FieldType::INT),
156-
PredicateBuilder::NotEqual(total_index, total_name, FieldType::INT,
154+
{selector,
155+
PredicateBuilder::IsNull(kTotalBucketsFieldIndex, total_name, FieldType::INT),
156+
PredicateBuilder::NotEqual(kTotalBucketsFieldIndex, total_name, FieldType::INT,
157157
Literal(expected_total_buckets.value()))}));
158158
}
159159
// Retain unsupported versions regardless of bucket so the consumer validates every version
160160
// before bucket filtering, including when the probe would otherwise select no entries.
161161
const std::string& version_name = target_type->field(kVersionFieldIndex)->name();
162-
const int32_t version_index = file_schema->GetFieldIndex(version_name);
163162
PAIMON_ASSIGN_OR_RAISE(
164163
selector,
165164
PredicateBuilder::Or(
166-
{selector, PredicateBuilder::IsNull(version_index, version_name, FieldType::INT),
165+
{selector, PredicateBuilder::IsNull(kVersionFieldIndex, version_name, FieldType::INT),
167166
PredicateBuilder::NotEqual(
168-
version_index, version_name, FieldType::INT,
167+
kVersionFieldIndex, version_name, FieldType::INT,
169168
Literal(
170169
checked_cast<ManifestEntrySerializer*>(serializer_.get())->GetVersion()))}));
171170
if (!PredicateValidator::ValidatePredicateWithSchema(*file_schema, selector,

‎src/paimon/core/manifest/manifest_file.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ class ManifestFile : public ObjectsFile<ManifestEntry> {
6464
Result<std::vector<ManifestFileMeta>> Write(const std::vector<ManifestEntry>& entries);
6565

6666
/// Read entries for a bucket. An inferred total bucket count also retains entries with
67-
/// different or unknown bucket counts for the existing compatibility checks.
68-
/// For inferred buckets, the caller must first verify that all historical bucket schemas
69-
/// covered by the manifest are compatible with the scan's bucket selector.
67+
/// different or unknown bucket counts for per-entry bucket filtering.
68+
/// Bucket pruning assumes stable bucket-key hashing across schema versions.
7069
/// Serialization versions are validated for all entries before bucket filtering.
70+
///
71+
/// @param file_size Length of the manifest when the caller already has it from the manifest
72+
/// list, which saves the read a metadata request on a remote store. Pass
73+
/// std::nullopt when the length is not known.
7174
Status ReadBucketEntries(const std::string& file_name, int32_t bucket,
7275
const std::optional<int32_t>& expected_total_buckets,
7376
std::optional<int64_t> file_size,

0 commit comments

Comments
 (0)