Skip to main content

uqa_sql/plan/memory/
assignments.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7use crate::ast::{
8    AssignmentStep, AssignmentTarget, AssignmentTargets, MultipleAssignmentTargets,
9    WindowDefinition,
10};
11use uqa_core::memory::{AllocationObserver, ObserveAllocations};
12use uqa_core::ValueRetentionError;
13
14impl<E: ObserveAllocations> ObserveAllocations for AssignmentTargets<E> {
15    fn observe_allocations<'a>(
16        &'a self,
17        observer: &mut AllocationObserver<'a, '_>,
18    ) -> Result<(), ValueRetentionError> {
19        match self {
20            Self::Single(target) => observer.child(target),
21            Self::Multiple(group) => observer.child(group),
22        }
23    }
24}
25
26impl<E: ObserveAllocations> ObserveAllocations for AssignmentTarget<E> {
27    fn observe_allocations<'a>(
28        &'a self,
29        observer: &mut AllocationObserver<'a, '_>,
30    ) -> Result<(), ValueRetentionError> {
31        let Self {
32            column,
33            indirection,
34        } = self;
35        observer.child(column)?;
36        observer.child(indirection)
37    }
38}
39
40impl<E: ObserveAllocations> ObserveAllocations for MultipleAssignmentTargets<E> {
41    fn observe_allocations<'a>(
42        &'a self,
43        observer: &mut AllocationObserver<'a, '_>,
44    ) -> Result<(), ValueRetentionError> {
45        let Self {
46            targets,
47            source_positions,
48            source_width: _,
49        } = self;
50        observer.child(targets)?;
51        observer.child(source_positions)
52    }
53}
54
55impl<E: ObserveAllocations> ObserveAllocations for AssignmentStep<E> {
56    fn observe_allocations<'a>(
57        &'a self,
58        observer: &mut AllocationObserver<'a, '_>,
59    ) -> Result<(), ValueRetentionError> {
60        match self {
61            Self::Field(name) => observer.child(name),
62            Self::Index(expression) => observer.child(expression),
63            Self::Slice { lower, upper } => {
64                observer.child(lower)?;
65                observer.child(upper)
66            }
67        }
68    }
69}
70
71impl<S: ObserveAllocations> ObserveAllocations for WindowDefinition<S> {
72    fn observe_allocations<'a>(
73        &'a self,
74        observer: &mut AllocationObserver<'a, '_>,
75    ) -> Result<(), ValueRetentionError> {
76        let Self {
77            name,
78            spec,
79            inherited: _,
80        } = self;
81        observer.child(name)?;
82        observer.child(spec)
83    }
84}