Skip to main content

datafusion_python/expr/
drop_function.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};
19use std::sync::Arc;
20
21use datafusion::logical_expr::DropFunction;
22use pyo3::IntoPyObjectExt;
23use pyo3::prelude::*;
24
25use super::logical_node::LogicalNode;
26use crate::common::df_schema::PyDFSchema;
27use crate::sql::logical::PyLogicalPlan;
28
29#[pyclass(
30    from_py_object,
31    frozen,
32    name = "DropFunction",
33    module = "datafusion.expr",
34    subclass
35)]
36#[derive(Clone)]
37pub struct PyDropFunction {
38    drop: DropFunction,
39}
40
41impl From<PyDropFunction> for DropFunction {
42    fn from(drop: PyDropFunction) -> Self {
43        drop.drop
44    }
45}
46
47impl From<DropFunction> for PyDropFunction {
48    fn from(drop: DropFunction) -> PyDropFunction {
49        PyDropFunction { drop }
50    }
51}
52
53impl Display for PyDropFunction {
54    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
55        write!(f, "DropFunction")
56    }
57}
58
59#[pymethods]
60impl PyDropFunction {
61    #[new]
62    fn new(name: String, schema: PyDFSchema, if_exists: bool) -> PyResult<Self> {
63        Ok(PyDropFunction {
64            drop: DropFunction {
65                name,
66                schema: Arc::new(schema.into()),
67                if_exists,
68            },
69        })
70    }
71    fn name(&self) -> PyResult<String> {
72        Ok(self.drop.name.clone())
73    }
74
75    fn schema(&self) -> PyDFSchema {
76        (*self.drop.schema).clone().into()
77    }
78
79    fn if_exists(&self) -> PyResult<bool> {
80        Ok(self.drop.if_exists)
81    }
82
83    fn __repr__(&self) -> PyResult<String> {
84        Ok(format!("DropFunction({self})"))
85    }
86
87    fn __name__(&self) -> PyResult<String> {
88        Ok("DropFunction".to_string())
89    }
90}
91
92impl LogicalNode for PyDropFunction {
93    fn inputs(&self) -> Vec<PyLogicalPlan> {
94        vec![]
95    }
96
97    fn to_variant<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
98        self.clone().into_bound_py_any(py)
99    }
100}