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