linkrs_query/executor/streaming/
parameters.rs1use std::collections::HashMap;
8
9use linkrs_core::types::operators::BinaryOperator;
10use linkrs_core::DataType;
11use linkrs_core::Value;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
15pub struct ParameterSlot(pub usize);
16
17#[derive(Debug, Clone)]
19pub struct ParameterDesc {
20 pub name: String,
21 pub slot: ParameterSlot,
22 pub value_type: Option<DataType>,
23 pub nullable: bool,
24 pub default: Option<Value>,
25}
26
27#[derive(Debug, Clone, Default)]
33pub struct ParameterSchema {
34 pub params: Vec<ParameterDesc>,
35 pub name_to_slot: HashMap<String, ParameterSlot>,
36}
37
38impl ParameterSchema {
39 pub fn new(params: Vec<ParameterDesc>) -> Self {
40 let name_to_slot = params.iter().map(|p| (p.name.clone(), p.slot)).collect();
41 Self {
42 params,
43 name_to_slot,
44 }
45 }
46
47 pub fn slot(&self, name: &str) -> Option<ParameterSlot> {
48 self.name_to_slot.get(name).copied()
49 }
50
51 pub fn len(&self) -> usize {
52 self.params.len()
53 }
54
55 pub fn is_empty(&self) -> bool {
56 self.params.is_empty()
57 }
58}
59
60#[derive(Debug, Clone)]
66pub struct ParameterFrame {
67 pub values: Vec<Value>,
68}
69
70impl ParameterFrame {
71 pub fn new(values: Vec<Value>) -> Self {
72 Self { values }
73 }
74
75 pub fn get(&self, slot: ParameterSlot) -> Option<&Value> {
76 self.values.get(slot.0)
77 }
78}
79
80#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
82pub struct SlotRef(pub usize);
83
84#[derive(Debug, Clone)]
91pub enum BoundExpression {
92 Literal(Value),
93 SlotRef(SlotRef),
94 ParameterRef(ParameterSlot),
95 Call {
96 name: String,
97 args: Vec<BoundExpression>,
98 },
99 Binary {
100 left: Box<BoundExpression>,
101 op: BinaryOperator,
102 right: Box<BoundExpression>,
103 },
104 Cast {
106 expr: Box<BoundExpression>,
107 target_type: DataType,
108 },
109}