Skip to content

Commit 8d12143

Browse files
committed
fix(registry): validate key column in scan_provider schema at registration
Add scan_provider.schema().index_of(key_col) guard in add_with_config to catch misconfigured registrations early instead of at query execution time.
1 parent d474463 commit 8d12143

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/registry.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,13 @@ impl USearchRegistry {
278278

279279
let _ = data_schema.index_of(key_col).map_err(|_| {
280280
DataFusionError::Execution(format!(
281-
"USearchRegistry: key column '{key_col}' not found in table '{name}' schema"
281+
"USearchRegistry: key column '{key_col}' not found in lookup provider schema for table '{name}'"
282+
))
283+
})?;
284+
285+
let _ = scan_provider.schema().index_of(key_col).map_err(|_| {
286+
DataFusionError::Execution(format!(
287+
"USearchRegistry: key column '{key_col}' not found in scan provider schema for table '{name}'"
282288
))
283289
})?;
284290

tests/execution.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,51 @@ async fn exec_qualified_where_order_by_alias() {
257257
assert_eq!(ids[0], 1, "closest alpha row must be row 1\nids: {ids:?}");
258258
}
259259

260+
// ═══════════════════════════════════════════════════════════════════════════════
261+
// Registration validation
262+
// ═══════════════════════════════════════════════════════════════════════════════
263+
264+
/// Registration must fail when scan_provider schema is missing the key column.
265+
#[tokio::test]
266+
async fn reg_scan_provider_missing_key_col_errors() {
267+
// scan_provider schema: only "label" and "vector" — no "id".
268+
let scan_schema = Arc::new(Schema::new(vec![
269+
Field::new("label", DataType::Utf8, false),
270+
Field::new(
271+
"vector",
272+
DataType::FixedSizeList(Arc::new(Field::new("item", DataType::Float32, true)), 4),
273+
false,
274+
),
275+
]));
276+
let scan_provider =
277+
Arc::new(HashKeyProvider::try_new(scan_schema, vec![], "label").expect("HashKeyProvider"));
278+
279+
// lookup_provider has "id".
280+
let lookup_schema = exec_schema();
281+
let lookup_provider =
282+
Arc::new(HashKeyProvider::try_new(lookup_schema, vec![], "id").expect("HashKeyProvider"));
283+
284+
let reg = USearchRegistry::new();
285+
let result = reg.add(
286+
"test::vector",
287+
make_populated_index(),
288+
scan_provider,
289+
lookup_provider,
290+
"id",
291+
MetricKind::L2sq,
292+
ScalarKind::F32,
293+
);
294+
assert!(
295+
result.is_err(),
296+
"registration must fail when scan_provider lacks key column"
297+
);
298+
let msg = result.unwrap_err().to_string();
299+
assert!(
300+
msg.contains("scan provider"),
301+
"error must mention scan provider: {msg}"
302+
);
303+
}
304+
260305
/// Qualified table, WHERE clause, ORDER BY UDF directly.
261306
#[tokio::test]
262307
async fn exec_qualified_where_order_by_udf() {

0 commit comments

Comments
 (0)