Remove uses of UserError::MissingPrimaryKey not related to inference

This commit is contained in:
Louis Dureuil 2022-12-19 15:59:22 +01:00
parent a8defb585b
commit 13c95d25aa
No known key found for this signature in database
2 changed files with 18 additions and 5 deletions

View File

@ -21,6 +21,10 @@ const DEFAULT_PRIMARY_KEY: &str = "id";
/// - all the documents id exist and are extracted,
/// - the validity of them but also,
/// - the validity of the `_geo` field depending on the settings.
///
/// # Panics
///
/// - if reader.is_empty(), this function may panic in some cases
pub fn enrich_documents_batch<R: Read + Seek>(
rtxn: &heed::RoTxn,
index: &Index,
@ -49,7 +53,7 @@ pub fn enrich_documents_batch<R: Read + Seek>(
primary_key: primary_key.to_string(),
document: obkv_to_object(&first_document, &documents_batch_index)?,
})),
None => Ok(Err(UserError::MissingPrimaryKey)),
None => unreachable!("Called with reader.is_empty()"),
};
}
},

View File

@ -16,7 +16,7 @@ use super::helpers::{create_sorter, create_writer, keep_latest_obkv, merge_obkvs
use super::{IndexDocumentsMethod, IndexerConfig};
use crate::documents::{DocumentsBatchIndex, EnrichedDocument, EnrichedDocumentsBatchReader};
use crate::error::{Error, InternalError, UserError};
use crate::index::db_name;
use crate::index::{db_name, main_key};
use crate::update::{AvailableDocumentsIds, ClearDocuments, UpdateIndexingStep};
use crate::{
ExternalDocumentsIds, FieldDistribution, FieldId, FieldIdMapMissingEntry, FieldsIdsMap, Index,
@ -459,7 +459,10 @@ impl<'a, 'i> Transform<'a, 'i> {
let primary_key = self
.index
.primary_key(wtxn)?
.ok_or(Error::UserError(UserError::MissingPrimaryKey))?
.ok_or(Error::InternalError(InternalError::DatabaseMissingEntry {
db_name: db_name::MAIN,
key: Some(main_key::PRIMARY_KEY_KEY),
}))?
.to_string();
let mut external_documents_ids = self.index.external_documents_ids(wtxn)?;
@ -557,8 +560,14 @@ impl<'a, 'i> Transform<'a, 'i> {
mut new_fields_ids_map: FieldsIdsMap,
) -> Result<TransformOutput> {
// There already has been a document addition, the primary key should be set by now.
let primary_key =
self.index.primary_key(wtxn)?.ok_or(UserError::MissingPrimaryKey)?.to_string();
let primary_key = self
.index
.primary_key(wtxn)?
.ok_or(InternalError::DatabaseMissingEntry {
db_name: db_name::MAIN,
key: Some(main_key::PRIMARY_KEY_KEY),
})?
.to_string();
let field_distribution = self.index.field_distribution(wtxn)?;
// Delete the soft deleted document ids from the maps inside the external_document_ids structure