polars_plan/dsl/
selector.rs

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
use std::ops::{Add, BitAnd, BitXor, Sub};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use super::*;

#[derive(Clone, PartialEq, Hash, Debug, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum Selector {
    Add(Box<Selector>, Box<Selector>),
    Sub(Box<Selector>, Box<Selector>),
    ExclusiveOr(Box<Selector>, Box<Selector>),
    Intersect(Box<Selector>, Box<Selector>),
    Root(Box<Expr>),
}

impl Selector {
    pub fn new(e: Expr) -> Self {
        Self::Root(Box::new(e))
    }
}

impl Add for Selector {
    type Output = Selector;

    fn add(self, rhs: Self) -> Self::Output {
        Selector::Add(Box::new(self), Box::new(rhs))
    }
}

impl BitAnd for Selector {
    type Output = Selector;

    #[allow(clippy::suspicious_arithmetic_impl)]
    fn bitand(self, rhs: Self) -> Self::Output {
        Selector::Intersect(Box::new(self), Box::new(rhs))
    }
}

impl BitXor for Selector {
    type Output = Selector;

    #[allow(clippy::suspicious_arithmetic_impl)]
    fn bitxor(self, rhs: Self) -> Self::Output {
        Selector::ExclusiveOr(Box::new(self), Box::new(rhs))
    }
}

impl Sub for Selector {
    type Output = Selector;

    #[allow(clippy::suspicious_arithmetic_impl)]
    fn sub(self, rhs: Self) -> Self::Output {
        Selector::Sub(Box::new(self), Box::new(rhs))
    }
}

impl From<&str> for Selector {
    fn from(value: &str) -> Self {
        Selector::new(col(PlSmallStr::from_str(value)))
    }
}

impl From<String> for Selector {
    fn from(value: String) -> Self {
        Selector::new(col(PlSmallStr::from_string(value)))
    }
}

impl From<PlSmallStr> for Selector {
    fn from(value: PlSmallStr) -> Self {
        Selector::new(Expr::Column(value))
    }
}

impl From<Expr> for Selector {
    fn from(value: Expr) -> Self {
        Selector::new(value)
    }
}