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