Skip to main content

datafusion_python/expr/
bool_expr.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;
21use pyo3::prelude::*;
22
23use super::PyExpr;
24
25#[pyclass(
26    from_py_object,
27    frozen,
28    name = "Not",
29    module = "datafusion.expr",
30    subclass
31)]
32#[derive(Clone, Debug)]
33pub struct PyNot {
34    expr: Expr,
35}
36
37impl PyNot {
38    pub fn new(expr: Expr) -> Self {
39        Self { expr }
40    }
41}
42
43impl Display for PyNot {
44    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
45        write!(
46            f,
47            "Not
48            Expr: {}",
49            &self.expr
50        )
51    }
52}
53
54#[pymethods]
55impl PyNot {
56    fn expr(&self) -> PyResult<PyExpr> {
57        Ok(self.expr.clone().into())
58    }
59}
60
61#[pyclass(
62    from_py_object,
63    frozen,
64    name = "IsNotNull",
65    module = "datafusion.expr",
66    subclass
67)]
68#[derive(Clone, Debug)]
69pub struct PyIsNotNull {
70    expr: Expr,
71}
72
73impl PyIsNotNull {
74    pub fn new(expr: Expr) -> Self {
75        Self { expr }
76    }
77}
78
79impl Display for PyIsNotNull {
80    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
81        write!(
82            f,
83            "IsNotNull
84            Expr: {}",
85            &self.expr
86        )
87    }
88}
89
90#[pymethods]
91impl PyIsNotNull {
92    fn expr(&self) -> PyResult<PyExpr> {
93        Ok(self.expr.clone().into())
94    }
95}
96
97#[pyclass(
98    from_py_object,
99    frozen,
100    name = "IsNull",
101    module = "datafusion.expr",
102    subclass
103)]
104#[derive(Clone, Debug)]
105pub struct PyIsNull {
106    expr: Expr,
107}
108
109impl PyIsNull {
110    pub fn new(expr: Expr) -> Self {
111        Self { expr }
112    }
113}
114
115impl Display for PyIsNull {
116    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
117        write!(
118            f,
119            "IsNull
120            Expr: {}",
121            &self.expr
122        )
123    }
124}
125
126#[pymethods]
127impl PyIsNull {
128    fn expr(&self) -> PyResult<PyExpr> {
129        Ok(self.expr.clone().into())
130    }
131}
132
133#[pyclass(
134    from_py_object,
135    frozen,
136    name = "IsTrue",
137    module = "datafusion.expr",
138    subclass
139)]
140#[derive(Clone, Debug)]
141pub struct PyIsTrue {
142    expr: Expr,
143}
144
145impl PyIsTrue {
146    pub fn new(expr: Expr) -> Self {
147        Self { expr }
148    }
149}
150
151impl Display for PyIsTrue {
152    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
153        write!(
154            f,
155            "IsTrue
156            Expr: {}",
157            &self.expr
158        )
159    }
160}
161
162#[pymethods]
163impl PyIsTrue {
164    fn expr(&self) -> PyResult<PyExpr> {
165        Ok(self.expr.clone().into())
166    }
167}
168
169#[pyclass(
170    from_py_object,
171    frozen,
172    name = "IsFalse",
173    module = "datafusion.expr",
174    subclass
175)]
176#[derive(Clone, Debug)]
177pub struct PyIsFalse {
178    expr: Expr,
179}
180
181impl PyIsFalse {
182    pub fn new(expr: Expr) -> Self {
183        Self { expr }
184    }
185}
186
187impl Display for PyIsFalse {
188    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
189        write!(
190            f,
191            "IsFalse
192            Expr: {}",
193            &self.expr
194        )
195    }
196}
197
198#[pymethods]
199impl PyIsFalse {
200    fn expr(&self) -> PyResult<PyExpr> {
201        Ok(self.expr.clone().into())
202    }
203}
204
205#[pyclass(
206    from_py_object,
207    frozen,
208    name = "IsUnknown",
209    module = "datafusion.expr",
210    subclass
211)]
212#[derive(Clone, Debug)]
213pub struct PyIsUnknown {
214    expr: Expr,
215}
216
217impl PyIsUnknown {
218    pub fn new(expr: Expr) -> Self {
219        Self { expr }
220    }
221}
222
223impl Display for PyIsUnknown {
224    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
225        write!(
226            f,
227            "IsUnknown
228            Expr: {}",
229            &self.expr
230        )
231    }
232}
233
234#[pymethods]
235impl PyIsUnknown {
236    fn expr(&self) -> PyResult<PyExpr> {
237        Ok(self.expr.clone().into())
238    }
239}
240
241#[pyclass(
242    from_py_object,
243    frozen,
244    name = "IsNotTrue",
245    module = "datafusion.expr",
246    subclass
247)]
248#[derive(Clone, Debug)]
249pub struct PyIsNotTrue {
250    expr: Expr,
251}
252
253impl PyIsNotTrue {
254    pub fn new(expr: Expr) -> Self {
255        Self { expr }
256    }
257}
258
259impl Display for PyIsNotTrue {
260    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
261        write!(
262            f,
263            "IsNotTrue
264            Expr: {}",
265            &self.expr
266        )
267    }
268}
269
270#[pymethods]
271impl PyIsNotTrue {
272    fn expr(&self) -> PyResult<PyExpr> {
273        Ok(self.expr.clone().into())
274    }
275}
276
277#[pyclass(
278    from_py_object,
279    frozen,
280    name = "IsNotFalse",
281    module = "datafusion.expr",
282    subclass
283)]
284#[derive(Clone, Debug)]
285pub struct PyIsNotFalse {
286    expr: Expr,
287}
288
289impl PyIsNotFalse {
290    pub fn new(expr: Expr) -> Self {
291        Self { expr }
292    }
293}
294
295impl Display for PyIsNotFalse {
296    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
297        write!(
298            f,
299            "IsNotFalse
300            Expr: {}",
301            &self.expr
302        )
303    }
304}
305
306#[pymethods]
307impl PyIsNotFalse {
308    fn expr(&self) -> PyResult<PyExpr> {
309        Ok(self.expr.clone().into())
310    }
311}
312
313#[pyclass(
314    from_py_object,
315    frozen,
316    name = "IsNotUnknown",
317    module = "datafusion.expr",
318    subclass
319)]
320#[derive(Clone, Debug)]
321pub struct PyIsNotUnknown {
322    expr: Expr,
323}
324
325impl PyIsNotUnknown {
326    pub fn new(expr: Expr) -> Self {
327        Self { expr }
328    }
329}
330
331impl Display for PyIsNotUnknown {
332    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
333        write!(
334            f,
335            "IsNotUnknown
336            Expr: {}",
337            &self.expr
338        )
339    }
340}
341
342#[pymethods]
343impl PyIsNotUnknown {
344    fn expr(&self) -> PyResult<PyExpr> {
345        Ok(self.expr.clone().into())
346    }
347}
348
349#[pyclass(
350    from_py_object,
351    frozen,
352    name = "Negative",
353    module = "datafusion.expr",
354    subclass
355)]
356#[derive(Clone, Debug)]
357pub struct PyNegative {
358    expr: Expr,
359}
360
361impl PyNegative {
362    pub fn new(expr: Expr) -> Self {
363        Self { expr }
364    }
365}
366
367impl Display for PyNegative {
368    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
369        write!(
370            f,
371            "Negative
372            Expr: {}",
373            &self.expr
374        )
375    }
376}
377
378#[pymethods]
379impl PyNegative {
380    fn expr(&self) -> PyResult<PyExpr> {
381        Ok(self.expr.clone().into())
382    }
383}