Skip to main content

tonbo_predicate/core/
operand.rs

1use std::sync::Arc;
2
3use super::ScalarValue;
4
5/// Reference identifying a column used inside predicates.
6///
7/// This is a logical column reference using only the column name.
8/// Physical binding (resolving to schema indices) happens during
9/// query planning, not at predicate construction time.
10#[derive(Clone, Debug, PartialEq, Eq, Hash)]
11pub struct ColumnRef {
12    /// Canonical column name.
13    pub name: Arc<str>,
14}
15
16impl ColumnRef {
17    /// Creates a new column reference from a name.
18    #[must_use]
19    pub fn new<N>(name: N) -> Self
20    where
21        N: Into<Arc<str>>,
22    {
23        Self { name: name.into() }
24    }
25}
26
27/// Operand used by predicate comparisons and function calls.
28#[derive(Clone, Debug, PartialEq)]
29pub enum Operand {
30    /// Reference to a column.
31    Column(ColumnRef),
32    /// Literal value.
33    Literal(ScalarValue),
34}
35
36impl From<ColumnRef> for Operand {
37    fn from(value: ColumnRef) -> Self {
38        Self::Column(value)
39    }
40}
41
42impl From<ScalarValue> for Operand {
43    fn from(value: ScalarValue) -> Self {
44        Self::Literal(value)
45    }
46}