This repository was archived by the owner on Dec 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathexpressions.rs
More file actions
68 lines (61 loc) · 2.29 KB
/
Copy pathexpressions.rs
File metadata and controls
68 lines (61 loc) · 2.29 KB
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
use super::{
GoalMemberId,
goal::Cost,
group::GroupId,
operators::{Child, Operator},
plans::PartialLogicalPlan,
};
use std::sync::Arc;
/// A logical expression in the memo structure.
///
/// Logical expressions have [`GroupId`]s as children rather than full plans, representing a compact
/// form suitable for the memo structure.
pub type LogicalExpression = Operator<GroupId>;
/// A unique identifier for a logical expression.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
pub struct LogicalExpressionId(pub i64);
/// A physical expression in the memo structure.
///
/// Physical expressions use [`Goal`]s rather than full plans for their children, representing a
/// compact form suitable for the memo structure.
pub type PhysicalExpression = Operator<GoalMemberId>;
/// A unique identifier for a physical expression.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
pub struct PhysicalExpressionId(pub i64);
/// An optimized physical expression with its associated cost.
#[derive(Clone, Debug)]
pub struct OptimizedExpression(pub PhysicalExpression, pub Cost);
impl From<LogicalExpression> for PartialLogicalPlan {
/// Converts a logical expression into a [`PartialLogicalPlan`].
///
/// This creates a materialized partial plan where each child group ID is converted to an
/// unmaterialized partial plan reference.
fn from(expr: LogicalExpression) -> Self {
PartialLogicalPlan::Materialized(Operator {
tag: expr.tag,
data: expr.data,
children: convert_children::<GroupId, Self>(expr.children),
})
}
}
/// A generic function that converts children with type `S` into a `Arc<T>`.
///
/// This handles both singleton and variable-length children, converting each source type into its
/// equivalent target wrapped in an [`Arc`].
fn convert_children<S, T>(children: Vec<Child<S>>) -> Vec<Child<Arc<T>>>
where
S: Into<T>,
{
children
.into_iter()
.map(|child| match child {
Child::Singleton(source) => Child::Singleton(Arc::new(source.into())),
Child::VarLength(sources) => Child::VarLength(
sources
.into_iter()
.map(|source| Arc::new(source.into()))
.collect(),
),
})
.collect()
}