feat: add Dataset.sample() with optional seed for deterministic sampling#6502
Open
beinan wants to merge 2 commits intolance-format:mainfrom
Open
feat: add Dataset.sample() with optional seed for deterministic sampling#6502beinan wants to merge 2 commits intolance-format:mainfrom
beinan wants to merge 2 commits intolance-format:mainfrom
Conversation
Add Dataset.sample() API to both Rust core and Java JNI, with an optional seed parameter for reproducible random sampling. When a seed is provided, uses StdRng::seed_from_u64 for deterministic index selection. Without a seed, sampling is non-deterministic using OS entropy. Useful for reproducible ML training/validation splits. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3 tasks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Dataset.sample()API to both Rust core and Java JNI for random row samplingseedparameter for deterministic sampling — same seed + same dataset state = same resultChanges
rust/lance/src/dataset.rs: Addseed: Option<u64>param toDataset::sample(); useStdRng::seed_from_u64when seeded,rand::rng()otherwiserust/lance/src/dataset/tests/dataset_io.rs: Addtest_sample_deterministic_with_seedverifying same seed = same result, different seed = different resultrust/lance/src/index/vector/utils.rs,rust/lance/src/dataset/write/merge_insert.rs,rust/lance/benches/take.rs: PassNonefor existing callers (backward compatible)java/lance-jni/src/blocking_dataset.rs: AddnativeSampleJNI functionjava/src/main/java/org/lance/Dataset.java: Addsample(n, columns),sample(n, columns, fragmentIds), andsample(n, columns, fragmentIds, seed)overloadsjava/src/test/java/org/lance/DatasetTest.java: Test basic sampling, fragment-filtered sampling, over-sampling, and deterministic sampling with seedTest plan
test_sample_deterministic_with_seed— same seed = identicalRecordBatch, different seed = different resulttest_sample_with_fragment_ids,test_sample_with_empty_fragment_ids_rejected,test_sample_with_unknown_fragment_ids_rejectedpass withNoneseedtestSample— basic sample, fragment-filtered sample, over-sample, deterministic seed verification🤖 Generated with Claude Code