1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//
// Unified Query Algebra
//
// Copyright (c) 2023-2026 Cognica, Inc.
//
//! Trailing routine identities preserve physical slots and carry independent controlled lookup metadata.
use crate::{
schema::{RowSchema, SchemaMap, NULL_SLOT},
SQLError,
};
use uqa_core::memory::ProductionControl;
impl RowSchema {
pub fn with_trailing_internal_aliases_with_control(
input: &Self,
trailing: &Self,
control: &ProductionControl<'_>,
) -> Result<Self, SQLError> {
control.check()?;
let offset = input
.physical_width()
.checked_sub(trailing.physical_width())
.expect("trailing internal-alias scope exceeds input row width");
for (column, slot) in &trailing.index.executor_attributes {
control.check()?;
if let Some(previous) = input.index.executor_attributes.get(column) {
assert_eq!(
*previous,
shifted(*slot, offset),
"structural identity moved between row scopes"
);
}
}
for (column, ty) in &trailing.index.cold.executor_attribute_types {
control.check()?;
if let Some(previous) = input.index.cold.executor_attribute_types.get(column) {
assert_eq!(
previous, ty,
"structural identity type changed between row scopes"
);
}
}
let mut metadata = super::copy::metadata(input, control)?;
metadata.internal = SchemaMap::from_produced(
input
.index
.executor_attributes
.iter()
.map(|(column, slot)| {
Ok((
control.finish(*column, control.empty_reservation())?,
control.finish(*slot, control.empty_reservation())?,
))
})
.chain(
trailing
.index
.executor_attributes
.iter()
.filter(|(column, _)| {
!input.index.executor_attributes.contains_key(*column)
})
.map(|(column, slot)| {
Ok((
control.finish(*column, control.empty_reservation())?,
control
.finish(shifted(*slot, offset), control.empty_reservation())?,
))
}),
),
control,
)?;
metadata.internal_types = SchemaMap::from_produced(
input
.index
.cold
.executor_attribute_types
.iter()
.map(|(column, ty)| {
Ok((
control.finish(*column, control.empty_reservation())?,
super::optional_type(ty.as_ref(), control)?,
))
})
.chain(
trailing
.index
.cold
.executor_attribute_types
.iter()
.filter(|(column, _)| {
!input
.index
.cold
.executor_attribute_types
.contains_key(*column)
})
.map(|(column, ty)| {
Ok((
control.finish(*column, control.empty_reservation())?,
super::optional_type(ty.as_ref(), control)?,
))
}),
),
control,
)?;
for (column, ty) in &trailing.index.cold.executor_attribute_types {
metadata.collations.internal_with_control(
*column,
trailing.internal_collation(*column),
ty.as_ref(),
control,
)?;
}
super::copy::with_metadata(input, metadata, control)
}
}
fn shifted(slot: usize, offset: usize) -> usize {
if slot == NULL_SLOT {
NULL_SLOT
} else {
offset + slot
}
}