JingsongLi commented on code in PR #800:
URL: https://github.com/apache/paimon-rust/pull/800#discussion_r3986223913
##########
crates/paimon/src/table/vindex_index_build_builder/planning.rs:
##########
@@ -45,3 +49,79 @@ pub(super) fn plan_vindex_shards(
"vindex",
)
}
+
+pub(super) fn plan_ivf_training_ranges(
+ shard: &VindexIndexShard,
+ training_rows: usize,
+) -> Result<Vec<RowRange>> {
+ let shard_rows = usize::try_from(checked_row_count(
+ shard.row_range_start,
+ shard.row_range_end,
+ )?)
+ .map_err(|error| Error::DataInvalid {
+ message: "vindex shard row count does not fit usize".to_string(),
+ source: Some(Box::new(error)),
+ })?;
+ if training_rows == 0 || training_rows > shard_rows {
+ return Err(Error::DataInvalid {
+ message: format!(
+ "Invalid IVF training row count: {training_rows}; shard
contains {shard_rows} rows"
+ ),
+ source: None,
+ });
+ }
+ if training_rows == shard_rows {
+ return Ok(Vec::new());
+ }
+
+ let range_count = training_rows.min(MAX_IVF_TRAINING_RANGES);
+ let gap_count = range_count + 1;
+ let skipped_rows = shard_rows - training_rows;
+ let seed = mix_seed(
+ (shard.snapshot_id as u64)
+ ^ (shard.row_range_start as u64).rotate_left(21)
+ ^ (shard.row_range_end as u64).rotate_left(42),
+ );
+ let range_extra_offset = seed as usize % range_count;
+ let gap_extra_offset = seed.rotate_left(17) as usize % gap_count;
+ let mut cursor = shard.row_range_start;
+ let mut ranges = Vec::with_capacity(range_count);
+
+ for gap_index in 0..range_count {
+ let gap = skipped_rows / gap_count
+ + usize::from(
+ (gap_index + gap_count - gap_extra_offset) % gap_count <
skipped_rows % gap_count,
+ );
+ cursor = checked_add_offset(cursor, gap, "training gap")?;
Review Comment:
Verified at 28d6670: both original tail-distribution cases (100,000 rows
with a final 500-row cluster, and 1,000,000 rows with a final 10,000-row
cluster) now return 10/10 correct-cluster results. The specific fixed-gap
regression described above is addressed. A separate small-sample case still
fails and is documented on the current planner line here:
https://github.com/apache/paimon-rust/pull/800#discussion_r3986221481
--
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]