datafusion_python/expr/
between.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use std::fmt::{self, Display, Formatter};
19
20use datafusion::logical_expr::expr::Between;
21use pyo3::prelude::*;
22
23use crate::expr::PyExpr;
24
25#[pyclass(frozen, name = "Between", module = "datafusion.expr", subclass)]
26#[derive(Clone)]
27pub struct PyBetween {
28    between: Between,
29}
30
31impl From<PyBetween> for Between {
32    fn from(between: PyBetween) -> Self {
33        between.between
34    }
35}
36
37impl From<Between> for PyBetween {
38    fn from(between: Between) -> PyBetween {
39        PyBetween { between }
40    }
41}
42
43impl Display for PyBetween {
44    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
45        write!(
46            f,
47            "Between
48            Expr: {:?}
49            Negated: {:?}
50            Low: {:?}
51            High: {:?}",
52            &self.between.expr, &self.between.negated, &self.between.low, &self.between.high
53        )
54    }
55}
56
57#[pymethods]
58impl PyBetween {
59    fn expr(&self) -> PyResult<PyExpr> {
60        Ok((*self.between.expr).clone().into())
61    }
62
63    fn negated(&self) -> PyResult<bool> {
64        Ok(self.between.negated)
65    }
66
67    fn low(&self) -> PyResult<PyExpr> {
68        Ok((*self.between.low).clone().into())
69    }
70
71    fn high(&self) -> PyResult<PyExpr> {
72        Ok((*self.between.high).clone().into())
73    }
74
75    fn __repr__(&self) -> String {
76        format!("{self}")
77    }
78}