Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ crate-type = ["cdylib", "staticlib", "rlib"]
# `lance_index::progress::IndexBuildProgress`; already in the graph
# transitively via lance-index.
async-trait = "0.1"
lance = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7", features = ["substrait"] }
lance-core = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance-file = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance-index = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance-io = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance-linalg = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance-table = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance-datafusion = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7", features = ["substrait"] }
lance = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19", features = ["substrait"] }
lance-core = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
lance-file = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
lance-index = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
lance-io = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
lance-linalg = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
lance-table = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
lance-datafusion = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19", features = ["substrait"] }
datafusion = { version = "54.0.0", default-features = false }
arrow = { version = "58.0.0", features = ["prettyprint", "ffi"] }
arrow-array = "58.0.0"
Expand All @@ -51,9 +51,9 @@ snafu = "0.9"
uuid = { version = "1", features = ["v4"] }

[dev-dependencies]
lance = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7", features = ["substrait"] }
lance-datagen = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance-file = { git = "https://github.com/lance-format/lance.git", rev = "356acb0d333c96e970f6f84b97314fc5bc4193f7" }
lance = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19", features = ["substrait"] }
lance-datagen = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
lance-file = { git = "https://github.com/lance-format/lance.git", rev = "db211492fc5cd9da5642d7234d9682de9be77c19" }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
arrow-array = "58.0.0"
arrow-schema = "58.0.0"
Expand Down
118 changes: 118 additions & 0 deletions tests/c_api_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7717,6 +7717,124 @@ fn test_scanner_nearest_filter_postfilter() {
unsafe { lance_dataset_close(ds) };
}

#[test]
fn test_scanner_nearest_full_snapshot_prefilter_statistics() {
for stable_row_ids in [false, true] {
let (_tmp, uri) = create_multi_fragment_vector_dataset(2, 32, 8, stable_row_ids);
let uri = c_str(&uri);
let dataset = unsafe { lance_dataset_open(uri.as_ptr(), ptr::null(), 0) };
assert!(!dataset.is_null());
let column = c_str("embedding");
let params = LanceVectorIndexParams {
index_type: LanceVectorIndexType::IvfFlat,
metric: LanceMetricType::L2,
num_partitions: 1,
num_sub_vectors: 0,
num_bits: 0,
max_iterations: 2,
hnsw_m: 0,
hnsw_ef_construction: 0,
sample_rate: 0,
};
assert_eq!(
unsafe {
lance_dataset_create_vector_index(
dataset,
column.as_ptr(),
ptr::null(),
&params,
false,
)
},
0
);
let mut fragments = [0_u64; 2];
assert_eq!(
unsafe { lance_dataset_fragment_ids(dataset, fragments.as_mut_ptr()) },
0
);

let mut reference_rows_scanned = None;
for scope in [None, Some(fragments.as_slice()), Some(&fragments[..1])] {
let scanner = unsafe { lance_scanner_new(dataset, ptr::null(), ptr::null()) };
assert!(!scanner.is_null());
if let Some(scope) = scope {
assert_eq!(
unsafe { lance_scanner_set_fragment_ids(scanner, scope.as_ptr(), scope.len()) },
0
);
}
let query = [60.0_f32; 8];
assert_eq!(
unsafe {
lance_scanner_nearest(
scanner,
column.as_ptr(),
query.as_ptr().cast(),
query.len(),
LanceDataType::Float32 as i32,
5,
)
},
0
);
assert_eq!(unsafe { lance_scanner_set_prefilter(scanner, true) }, 0);
let mut captured = CapturedScanStatistics::default();
assert_eq!(
unsafe {
lance_scanner_set_statistics_callback(
scanner,
Some(capture_scan_statistics),
(&mut captured as *mut CapturedScanStatistics).cast(),
)
},
0
);
let batches = scan_all_rows_from_scanner(scanner);
let mut ids = batches
.iter()
.flat_map(|batch| {
batch
.column_by_name("id")
.unwrap()
.as_any()
.downcast_ref::<Int32Array>()
.unwrap()
.values()
.to_vec()
})
.collect::<Vec<_>>();
ids.sort_unstable();
assert_eq!(captured.calls, 1);
let count = |name: &str| {
captured
.metrics
.iter()
.filter(|(key, kind, _)| key == name && *kind == LanceScanMetricKind::Count)
.map(|(_, _, value)| *value)
.sum::<u64>()
};
if scope.is_some_and(|scope| scope.len() == 1) {
assert_eq!(ids, vec![27, 28, 29, 30, 31]);
assert_eq!(count("prefilter_input_rows"), 32);
assert_eq!(count("prefilter_row_ids"), 32);
} else {
assert_eq!(ids, vec![58, 59, 60, 61, 62]);
assert_eq!(count("prefilter_input_rows"), 0);
// Equal results alone would miss a redundant scan of every row ID.
let rows_scanned = count("rows_scanned");
if let Some(reference) = reference_rows_scanned {
assert_eq!(rows_scanned, reference);
} else {
reference_rows_scanned = Some(rows_scanned);
}
}
unsafe { lance_scanner_close(scanner) };
}
unsafe { lance_dataset_close(dataset) };
}
}

#[test]
fn test_scanner_nearest_prefilter_with_fragment_ids_next() {
let (_tmp, uri) = create_multi_fragment_vector_dataset(2, 32, 8, false);
Expand Down
Loading