Skip to main content

uqa_execution/mutation/point_update/
context.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Services for an atomic point-identified mutation.
8use crate::{
9    mutation::{
10        assignment::MutationAssignmentContext,
11        command_scope::{CommandScopeSource, MutationCommandState},
12        constraints::ConstraintContext,
13    },
14    query::locking::context::RowLockContext,
15};
16use std::collections::BTreeMap;
17use uqa_core::{DocId, Value};
18use uqa_sql::SQLError;
19pub type RowUpdateVectors = BTreeMap<String, Vec<Vec<f32>>>;
20pub type RowIndependentUpdateValues = (BTreeMap<String, Value>, RowUpdateVectors);
21pub trait PointMutationStorage {
22    fn find_doc_id_by_field(
23        &self,
24        table: &str,
25        field: &str,
26        value: &Value,
27    ) -> Result<Option<DocId>, SQLError>;
28    /// Patch the same command-visible version as the identity lookup, including an unpublished row; a command tombstone is absent.
29    fn patch_document_fields_with_vector_values(
30        &self,
31        table: &str,
32        doc_id: DocId,
33        updates: &BTreeMap<String, Value>,
34        vectors: &RowUpdateVectors,
35    ) -> Result<bool, SQLError>;
36}
37#[derive(Clone)]
38pub struct PointMutationContext<'a, S: Clone + 'static> {
39    pub observations: &'a dyn crate::serializable::SerializableWrites,
40    pub assignment: MutationAssignmentContext<'a, S>,
41    pub constraints: ConstraintContext<'a>,
42    pub locking: RowLockContext<'a, S>,
43    pub scopes: &'a dyn CommandScopeSource<S>,
44    pub transaction: &'a dyn MutationCommandState,
45    pub storage: &'a dyn PointMutationStorage,
46}
47impl<S: Clone + 'static> Copy for PointMutationContext<'_, S> {}