Skip to main content

datafusion_python/expr/
drop_view.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::DropView;
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 = "DropView",
33    module = "datafusion.expr",
34    subclass
35)]
36#[derive(Clone)]
37pub struct PyDropView {
38    drop: DropView,
39}
40
41impl From<PyDropView> for DropView {
42    fn from(drop: PyDropView) -> Self {
43        drop.drop
44    }
45}
46
47impl From<DropView> for PyDropView {
48    fn from(drop: DropView) -> PyDropView {
49        PyDropView { drop }
50    }
51}
52
53impl Display for PyDropView {
54    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
55        write!(
56            f,
57            "DropView: {name:?} if not exist:={if_exists}",
58            name = self.drop.name,
59            if_exists = self.drop.if_exists
60        )
61    }
62}
63
64#[pymethods]
65impl PyDropView {
66    #[new]
67    fn new(name: String, schema: PyDFSchema, if_exists: bool) -> PyResult<Self> {
68        Ok(PyDropView {
69            drop: DropView {
70                name: name.into(),
71                schema: Arc::new(schema.into()),
72                if_exists,
73            },
74        })
75    }
76
77    fn name(&self) -> PyResult<String> {
78        Ok(self.drop.name.to_string())
79    }
80
81    fn schema(&self) -> PyDFSchema {
82        (*self.drop.schema).clone().into()
83    }
84
85    fn if_exists(&self) -> PyResult<bool> {
86        Ok(self.drop.if_exists)
87    }
88
89    fn __repr__(&self) -> PyResult<String> {
90        Ok(format!("DropView({self})"))
91    }
92
93    fn __name__(&self) -> PyResult<String> {
94        Ok("DropView".to_string())
95    }
96}
97
98impl LogicalNode for PyDropView {
99    fn inputs(&self) -> Vec<PyLogicalPlan> {
100        vec![]
101    }
102
103    fn to_variant<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
104        self.clone().into_bound_py_any(py)
105    }
106}