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