diff --git a/src/cache/change_set.rs b/src/cache/change_set.rs index 5abd6b8..bbf36f1 100644 --- a/src/cache/change_set.rs +++ b/src/cache/change_set.rs @@ -25,9 +25,14 @@ impl ChangeSet { } } + /// Create new `ChangeSet + pub fn new_with_operations(id: SnapshotId, operations: SchemaBatch) -> Self { + Self { id, operations } + } + /// Get value from its own cache pub fn get(&self, key: &impl KeyCodec) -> anyhow::Result> { - self.operations.get(key) + self.operations.get_operation(key) } /// Get the ID of this [`ChangeSet`]. diff --git a/src/schema_batch.rs b/src/schema_batch.rs index f47b716..604f1b6 100644 --- a/src/schema_batch.rs +++ b/src/schema_batch.rs @@ -50,7 +50,8 @@ impl SchemaBatch { column_writes.insert(key, operation); } - pub(crate) fn get( + /// Getting the operation from current schema batch if present + pub(crate) fn get_operation( &self, key: &impl KeyCodec, ) -> anyhow::Result> { @@ -63,6 +64,17 @@ impl SchemaBatch { } } + /// Getting value by key if it was written in this batch. + /// Deleted operation will return None as well as missing key + pub fn get_value(&self, key: &impl KeyCodec) -> anyhow::Result> { + let operation = self.get_operation(key)?; + if let Some(operation) = operation { + let value = operation.decode_value::()?; + return Ok(value); + } + Ok(None) + } + /// Iterator over all values in lexicographic order. pub fn iter(&self) -> btree_map::Iter { self.last_writes @@ -319,7 +331,7 @@ mod tests { let get_value = |field: &TestField| -> Option { batch1 - .get::(field) + .get_operation::(field) .unwrap() .unwrap() .decode_value::()