fix: return error instead of panicking on values too wide for miniblock#7650
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
yanghua
left a comment
There was a problem hiding this comment.
Left two comments you can consider.
| assert!(size_bytes < MAX_MINIBLOCK_BYTES); | ||
| if size_bytes >= MAX_MINIBLOCK_BYTES { | ||
| return Err(Error::invalid_input(format!( | ||
| "Value is too wide for miniblock encoding: 2 values require {} bytes but a \ |
There was a problem hiding this comment.
Is there always 2 values? May it be 16?
If the answer is yes, I'd suggest that we do not hardcode.
| } | ||
|
|
||
| #[test] | ||
| fn test_wide_value_miniblock_returns_error() { |
There was a problem hiding this comment.
Maybe we also need to add a test for fxl?
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThe ValueEncoder miniblock path now returns explicit ChangesValueEncoder Result-based error handling
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant Compress as MiniBlockCompressor::compress
participant ChunkData as chunk_data / miniblock_fsl
participant Finder as find_log_vals_per_chunk
Compress->>ChunkData: chunk_data(fixed_width) / miniblock_fsl(chunk)
ChunkData->>Finder: find_log_vals_per_chunk(...)
Finder-->>ChunkData: Err(InvalidInput) if size exceeds MAX_MINIBLOCK_BYTES
ChunkData-->>Compress: propagate Err via ?
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
rust/lance-encoding/src/encodings/physical/value.rs (1)
30-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDocument the "2 * values_per_word" minimum-chunk rationale.
The width-check and its
num_values = 2 * values_per_wordcalculation encode an important invariant (minimum viable miniblock chunk is 2 words, i.e. 2 or 16 values depending on word size) that previously caused reviewer confusion (see past comment asking "Is there always 2 values? May it be 16?"). The current code correctly generalizes this, but a short inline comment explaining why the minimum is2 * values_per_word(rather than 1) would prevent the same question from resurfacing for future readers.📝 Suggested doc comment
fn find_log_vals_per_chunk(bytes_per_word, values_per_word) -> Result<(u64, u64)> { let mut size_bytes = 2 * bytes_per_word; let (mut log_num_vals, mut num_vals) = match values_per_word { 1 => (1, 2), 8 => (3, 8), _ => unreachable!(), }; + // A miniblock chunk must hold at least 2 words worth of values (log_num_values >= 1), + // so the smallest possible chunk requires `2 * values_per_word` values. If even that + // minimum doesn't fit, the value is too wide to encode as a miniblock at all. if size_bytes >= MAX_MINIBLOCK_BYTES { let num_values = 2 * values_per_word;As per coding guidelines, "Add doc comments to magic constants, thresholds, and non-obvious transformation functions, explaining what the value represents and why it was chosen."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@rust/lance-encoding/src/encodings/physical/value.rs` around lines 30 - 54, Add a short inline comment in find_log_vals_per_chunk explaining why the minimum miniblock chunk is modeled as 2 * values_per_word, since the width check and num_values calculation rely on that invariant. Clarify that the smallest viable chunk is two words, which corresponds to 2 values for 1-word types or 16 values for 8-word types, so future readers understand why the threshold is not a single word.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@rust/lance-encoding/src/encodings/physical/value.rs`:
- Around line 30-54: Add a short inline comment in find_log_vals_per_chunk
explaining why the minimum miniblock chunk is modeled as 2 * values_per_word,
since the width check and num_values calculation rely on that invariant. Clarify
that the smallest viable chunk is two words, which corresponds to 2 values for
1-word types or 16 values for 8-word types, so future readers understand why the
threshold is not a single word.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 55fa1469-8e84-4b76-8509-8621336448d1
📒 Files selected for processing (1)
rust/lance-encoding/src/encodings/physical/value.rs
Return error instead of panicking on values too wide for miniblock
Summary by CodeRabbit
InvalidInputerror instead of failing unexpectedly.