Skip to content

Commit 8c90381

Browse files
fix: use i64 for index file size (#586)
1 parent 2b8f908 commit 8c90381

15 files changed

Lines changed: 66 additions & 31 deletions

bindings/c/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1764,7 +1764,7 @@ fn build_pk_vector_table(path: &str, vectors: &[[f32; PK_DIM]]) -> Table {
17641764
let index_file = IndexFileMeta {
17651765
index_type: INDEX_TYPE.to_string(),
17661766
file_name: index_file_name,
1767-
file_size: i32::try_from(index_file_size).unwrap(),
1767+
file_size: i64::try_from(index_file_size).unwrap(),
17681768
row_count: i32::try_from(row_count).unwrap(),
17691769
deletion_vectors_ranges: None,
17701770
global_index_meta: Some(GlobalIndexMeta {

crates/integrations/datafusion/src/system_tables/table_indexes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl TableProvider for TableIndexesTable {
131131
buckets.push(entry.bucket);
132132
index_types.push(index_file.index_type.as_str());
133133
file_names.push(index_file.file_name.as_str());
134-
file_sizes.push(i64::from(index_file.file_size));
134+
file_sizes.push(index_file.file_size);
135135
row_counts.push(i64::from(index_file.row_count));
136136
append_dv_ranges(
137137
&mut dv_ranges,

crates/integrations/datafusion/tests/system_tables.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,7 @@ async fn test_table_indexes_system_table() {
286286
assert_eq!(buckets.value(row), expected.bucket);
287287
assert_eq!(index_types.value(row), expected.index_file.index_type);
288288
assert_eq!(file_names.value(row), expected.index_file.file_name);
289-
assert_eq!(
290-
file_sizes.value(row),
291-
i64::from(expected.index_file.file_size)
292-
);
289+
assert_eq!(file_sizes.value(row), expected.index_file.file_size);
293290
assert_eq!(
294291
row_counts.value(row),
295292
i64::from(expected.index_file.row_count)

crates/paimon/src/spec/avro/index_manifest_entry_decode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl AvroRecordDecode for IndexManifestEntry {
3535
let mut bucket: Option<i32> = None;
3636
let mut index_type: Option<String> = None;
3737
let mut file_name: Option<String> = None;
38-
let mut file_size: Option<i32> = None;
38+
let mut file_size: Option<i64> = None;
3939
let mut row_count: Option<i32> = None;
4040
let mut deletion_vectors_ranges: Option<IndexMap<String, DeletionVectorMeta>> = None;
4141
let mut global_index_meta: Option<GlobalIndexMeta> = None;
@@ -60,7 +60,7 @@ impl AvroRecordDecode for IndexManifestEntry {
6060
"_BUCKET" => bucket = Some(read_int_field(cursor, field.nullable)?),
6161
"_INDEX_TYPE" => index_type = Some(read_string_field(cursor, field.nullable)?),
6262
"_FILE_NAME" => file_name = Some(read_string_field(cursor, field.nullable)?),
63-
"_FILE_SIZE" => file_size = Some(read_long_field(cursor, field.nullable)? as i32),
63+
"_FILE_SIZE" => file_size = Some(read_long_field(cursor, field.nullable)?),
6464
"_ROW_COUNT" => row_count = Some(read_long_field(cursor, field.nullable)? as i32),
6565
"_DELETIONS_VECTORS_RANGES" | "_DELETION_VECTORS_RANGES" => {
6666
deletion_vectors_ranges = decode_nullable_dv_ranges(cursor, field.nullable)?;

crates/paimon/src/spec/index_file_meta.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub struct IndexFileMeta {
6363
pub file_name: String,
6464

6565
#[serde(rename = "_FILE_SIZE")]
66-
pub file_size: i32,
66+
pub file_size: i64,
6767

6868
#[serde(rename = "_ROW_COUNT")]
6969
pub row_count: i32,

crates/paimon/src/spec/index_manifest.rs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ use crate::Result;
2727
///
2828
/// Must match the serde layout of `IndexManifestEntry`.
2929
///
30-
/// Note: `_FILE_SIZE` and `_ROW_COUNT` are declared as Avro `long` to match
31-
/// Java Paimon's schema, while the Rust `IndexFileMeta` fields are `i32`.
32-
/// `serde_avro_fast` transparently coerces between integer widths during
33-
/// serialization/deserialization, so the mismatch is intentional.
30+
/// Note: `_FILE_SIZE` is an Avro `long` and Rust `i64`, matching Java Paimon's
31+
/// schema. `_ROW_COUNT` remains an Avro `long` for Java compatibility while
32+
/// the Rust `IndexFileMeta` field is still `i32`.
3433
pub const INDEX_MANIFEST_ENTRY_SCHEMA: &str = r#"{
3534
"type": "record",
3635
"name": "org.apache.paimon.avro.generated.record",
@@ -345,6 +344,32 @@ mod tests {
345344
);
346345
}
347346

347+
#[test]
348+
fn file_size_above_i32_max_round_trips_through_index_manifest() {
349+
let file_size = i64::from(i32::MAX) + 1;
350+
let entry: IndexManifestEntry = serde_json::from_value(serde_json::json!({
351+
"_VERSION": 1,
352+
"_KIND": 0,
353+
"_PARTITION": [0, 0, 0, 0],
354+
"_BUCKET": 0,
355+
"_INDEX_TYPE": "TEST",
356+
"_FILE_NAME": "index",
357+
"_FILE_SIZE": file_size,
358+
"_ROW_COUNT": 1
359+
}))
360+
.unwrap();
361+
362+
let bytes = crate::spec::to_avro_bytes_with_compression(
363+
INDEX_MANIFEST_ENTRY_SCHEMA,
364+
std::slice::from_ref(&entry),
365+
crate::spec::DEFAULT_AVRO_COMPRESSION,
366+
)
367+
.unwrap();
368+
369+
let decoded = IndexManifest::read_from_bytes(&bytes).unwrap();
370+
assert_eq!(decoded, vec![entry]);
371+
}
372+
348373
#[test]
349374
fn legacy_five_field_global_index_decodes_without_source_meta() {
350375
// 5-field _GLOBAL_INDEX schema (pre-#8549): no _SOURCE_META. Identical to

crates/paimon/src/table/btree_global_index_build_builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<'a> BTreeGlobalIndexBuildBuilder<'a> {
275275
Ok(IndexFileMeta {
276276
index_type: index_type.to_string(),
277277
file_name,
278-
file_size: checked_i32(
278+
file_size: checked_i64(
279279
status.size,
280280
"Index file is too large for Rust IndexFileMeta",
281281
)?,
@@ -733,8 +733,8 @@ fn sort_index_rows(rows: &mut [BTreeKeyRow], cmp: &dyn Fn(&[u8], &[u8]) -> Order
733733
});
734734
}
735735

736-
fn checked_i32(value: u64, context: &str) -> Result<i32> {
737-
i32::try_from(value).map_err(|_| Error::DataInvalid {
736+
fn checked_i64(value: u64, context: &str) -> Result<i64> {
737+
i64::try_from(value).map_err(|_| Error::DataInvalid {
738738
message: format!("{context}: {value}"),
739739
source: None,
740740
})

crates/paimon/src/table/bucket_assigner_dynamic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ impl HashIndexFile {
8080
buf.extend_from_slice(&h.to_be_bytes());
8181
}
8282

83-
let file_size: i32 = buf
83+
let file_size: i64 = buf
8484
.len()
8585
.try_into()
86-
.expect("hash index file size exceeds i32::MAX");
86+
.expect("hash index file size exceeds i64::MAX");
8787
let output = file_io.new_output(&path)?;
8888
output.write(bytes::Bytes::from(buf)).await?;
8989

crates/paimon/src/table/data_evolution_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ impl DataEvolutionDeleteWriter {
689689
bytes.extend_from_slice(&serialized);
690690
}
691691

692-
let file_size = i32::try_from(bytes.len()).map_err(|_| crate::Error::DataInvalid {
692+
let file_size = i64::try_from(bytes.len()).map_err(|_| crate::Error::DataInvalid {
693693
message: "Deletion-vector index file is too large".to_string(),
694694
source: None,
695695
})?;

crates/paimon/src/table/global_index_scanner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl GlobalIndexScanner {
211211
BITMAP_GLOBAL_INDEX_TYPE => GlobalIndexFileKind::Bitmap,
212212
_ => unreachable!("normalized sorted global index type"),
213213
},
214-
file_size: i64::from(entry.index_file.file_size),
214+
file_size: entry.index_file.file_size,
215215
row_range_start: global_meta.row_range_start,
216216
meta: sorted_meta,
217217
};

0 commit comments

Comments
 (0)