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

Commit

Permalink
Constify the default primary key name
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerollmops committed Jul 12, 2022
1 parent 5f1bfb7 commit 7425430
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions milli/src/update/index_documents/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ use crate::{FieldId, Index, Object, Result};
/// The symbol used to define levels in a nested primary key.
const PRIMARY_KEY_SPLIT_SYMBOL: char = '.';

/// The default primary that is used when not specified.
const DEFAULT_PRIMARY_KEY: &str = "id";

/// This function validates and enrich the documents by checking that:
/// - we can infer a primary key,
/// - all the documents id exist and are extracted,
Expand Down Expand Up @@ -51,13 +54,14 @@ pub fn validate_and_enrich_documents_batch<R: Read + Seek>(
None => {
let guessed = documents_batch_index
.iter()
.filter(|(_, name)| name.to_lowercase().contains("id"))
.filter(|(_, name)| name.to_lowercase().contains(DEFAULT_PRIMARY_KEY))
.min_by_key(|(fid, _)| *fid);
match guessed {
Some((id, name)) => PrimaryKey::flat(name.as_str(), *id),
None if autogenerate_docids => {
PrimaryKey::flat("id", documents_batch_index.insert("id"))
}
None if autogenerate_docids => PrimaryKey::flat(
DEFAULT_PRIMARY_KEY,
documents_batch_index.insert(DEFAULT_PRIMARY_KEY),
),
None => return Ok(Err(UserError::MissingPrimaryKey)),
}
}
Expand Down

0 comments on commit 7425430

Please sign in to comment.