From 591053c55753e00341bd739c00f9ff09ae6e8141 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 10 Feb 2025 18:17:40 +0200 Subject: Remove typechecking --- log_db/src/engine.rs | 86 ++++++++++++++-------------------------------------- 1 file changed, 23 insertions(+), 63 deletions(-) (limited to 'log_db/src/engine.rs') diff --git a/log_db/src/engine.rs b/log_db/src/engine.rs index 62a88cb..d593053 100644 --- a/log_db/src/engine.rs +++ b/log_db/src/engine.rs @@ -68,7 +68,7 @@ impl Engine { let primary_key_index = config .schema .iter() - .position(|(field, _)| field == &config.primary_key) + .position(|field| field == &config.primary_key) .ok_or(DBError::ValidationError( "Primary key not found in schema after initialize".to_owned(), ))?; @@ -80,14 +80,9 @@ impl Engine { // If any of the keys is not in the schema or // is not an IndexableValue, return an error for &key in &all_keys { - let (_, value_type) = config.schema.iter().find(|(field, _)| field == key).ok_or( + let _ = config.schema.iter().find(|&field| field == key).ok_or( DBError::ValidationError("Key must be present in the field schema".to_owned()), )?; - - match value_type.primitive { - PrimitiveType::Int | PrimitiveType::String => {} - _ => return Err(DBError::ValidationError("Key must be indexable".to_owned())), - } } let primary_memtable = PrimaryMemtable::new(); let secondary_memtables = config @@ -163,9 +158,6 @@ impl Engine { for ForwardLogReaderItem { record, index } in ForwardLogReader::new_with_index(metadata_file, data_file, from_index) { - // Validate that the values in the record are compatible with the schema - record.validate(&self.config.schema)?; - let log_key = LogKey::new(segnum, index); if record.tombstone { @@ -200,7 +192,7 @@ impl Engine { .config .schema .iter() - .position(|(f, _)| sk_field == f) + .position(|f| sk_field == f) .unwrap(); let sk = record.at(sk_field_index).as_indexable().unwrap(); @@ -221,7 +213,7 @@ impl Engine { .config .schema .iter() - .position(|(f, _)| sk_field == f) + .position(|f| sk_field == f) .unwrap(); let sk = record.at(sk_field_index).as_indexable().unwrap(); @@ -258,22 +250,11 @@ impl Engine { field: &F, values: impl Iterator, ) -> DBResult> { - let field_type = self.get_field_type(field).ok_or(DBError::ValidationError( - "Field not found in schema".to_owned(), - ))?; - let indexables = values .map(|value| { - if type_check(&value, &field_type) { - value.as_indexable().ok_or(DBError::ValidationError( - "Queried value must be indexable".to_owned(), - )) - } else { - Err(DBError::ValidationError(format!( - "Queried value {:?} does not match key type: {:?}", - value, field_type - ))) - } + value.as_indexable().ok_or(DBError::ValidationError( + "Queried value must be indexable".to_owned(), + )) }) .collect::>>()?; @@ -396,35 +377,26 @@ impl Engine { field: &F, range: B, ) -> DBResult> { - fn range_bound_to_indexable( - bound: Bound<&Value>, - field_type: &Type, - ) -> DBResult> { - fn convert(value: &Value, field_type: &Type) -> DBResult { - if !type_check(&value, field_type) { - return Err(DBError::ValidationError(format!( - "Queried value does not match type: {:?}", - field_type - ))); - } - value.as_indexable().ok_or(DBError::ValidationError( - "Queried value must be indexable".to_owned(), - )) - } - + fn range_bound_to_indexable(bound: Bound<&Value>) -> DBResult> { match bound { - Bound::Included(value) => convert(value, field_type).map(Bound::Included), - Bound::Excluded(value) => convert(value, field_type).map(Bound::Excluded), + Bound::Included(value) => value + .as_indexable() + .ok_or(DBError::ValidationError( + "Queried value must be indexable".to_owned(), + )) + .map(Bound::Included), + Bound::Excluded(value) => value + .as_indexable() + .ok_or(DBError::ValidationError( + "Queried value must be indexable".to_owned(), + )) + .map(Bound::Excluded), Bound::Unbounded => Ok(Bound::Unbounded), } } - let field_type = self.get_field_type(field).ok_or(DBError::ValidationError( - "Field not found in schema".to_owned(), - ))?; - - let start_indexable = range_bound_to_indexable(range.start_bound(), field_type)?; - let end_indexable = range_bound_to_indexable(range.end_bound(), field_type)?; + let start_indexable = range_bound_to_indexable(range.start_bound())?; + let end_indexable = range_bound_to_indexable(range.end_bound())?; let indexable_bounds = OwnedBounds::new(start_indexable, end_indexable); @@ -705,15 +677,6 @@ impl Engine { Ok(()) } - #[inline] - fn get_field_type(&self, field: &F) -> Option<&Type> { - self.config - .schema - .iter() - .find(|(f, _)| f == field) - .map(|(_, t)| t) - } - #[inline] pub fn with_exclusive_lock( &mut self, @@ -801,10 +764,7 @@ mod tests { let mut db = DB::configure() .data_dir(data_dir.to_str().unwrap()) - .schema(vec![ - (Field::Id, Type::int()), - (Field::Name, Type::string()), - ]) + .fields(vec![Field::Id, Field::Name]) .primary_key(Field::Id) .secondary_keys(vec![Field::Name]) .from_record(TestInst2::from_record) -- cgit v1.3