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 crate::expr::PyExpr;
19use datafusion::logical_expr::expr::Between;
20use pyo3::prelude::*;
21use std::fmt::{self, Display, Formatter};
22
23#[pyclass(name = "Between", module = "datafusion.expr", subclass)]
24#[derive(Clone)]
25pub struct PyBetween {
26    between: Between,
27}
28
29impl From<PyBetween> for Between {
30    fn from(between: PyBetween) -> Self {
31        between.between
32    }
33}
34
35impl From<Between> for PyBetween {
36    fn from(between: Between) -> PyBetween {
37        PyBetween { between }
38    }
39}
40
41impl Display for PyBetween {
42    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
43        write!(
44            f,
45            "Between
46            Expr: {:?}
47            Negated: {:?}
48            Low: {:?}
49            High: {:?}",
50            &self.between.expr, &self.between.negated, &self.between.low, &self.between.high
51        )
52    }
53}
54
55#[pymethods]
56impl PyBetween {
57    fn expr(&self) -> PyResult<PyExpr> {
58        Ok((*self.between.expr).clone().into())
59    }
60
61    fn negated(&self) -> PyResult<bool> {
62        Ok(self.between.negated)
63    }
64
65    fn low(&self) -> PyResult<PyExpr> {
66        Ok((*self.between.low).clone().into())
67    }
68
69    fn high(&self) -> PyResult<PyExpr> {
70        Ok((*self.between.high).clone().into())
71    }
72
73    fn __repr__(&self) -> String {
74        format!("{}", self)
75    }
76}