Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Add primary_key_inference test
Browse files Browse the repository at this point in the history
  • Loading branch information
dureuill committed Dec 20, 2022
1 parent f1db571 commit 36fd2de
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions milli/src/update/index_documents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,56 @@ mod tests {
index.add_documents(doc4).unwrap_err();
}

#[test]
fn primary_key_inference() {
let index = TempIndex::new();

let doc_no_id = documents! {[{
"title": "asdsad",
"state": "automated",
"priority": "normal",
"branch_id_number": 0
}]};
assert!(matches!(
index.add_documents(doc_no_id),
Err(Error::UserError(UserError::NoPrimaryKeyCandidateFound))
));

let doc_multiple_ids = documents! {[{
"id": 228143,
"title": "something",
"state": "automated",
"priority": "normal",
"public_uid": "39c6499b",
"project_id": 78207,
"branch_id_number": 0
}]};

let Err(Error::UserError(UserError::MultiplePrimaryKeyCandidatesFound {
candidates
})) =
index.add_documents(doc_multiple_ids) else { panic!("Expected Error::UserError(MultiplePrimaryKeyCandidatesFound)") };

assert_eq!(candidates, vec![S("id"), S("public_uid"), S("project_id"),]);

let doc_inferable = documents! {[{
"video": "test.mp4",
"id": 228143,
"title": "something",
"state": "automated",
"priority": "normal",
"public_uid_": "39c6499b",
"project_id_": 78207,
"branch_id_number": 0
}]};

index.add_documents(doc_inferable).unwrap();

let txn = index.read_txn().unwrap();

assert_eq!(index.primary_key(&txn).unwrap().unwrap(), "id");
}

#[test]
fn long_words_must_be_skipped() {
let index = TempIndex::new();
Expand Down

0 comments on commit 36fd2de

Please sign in to comment.