datafusion_python/expr/
drop_view.rs1use 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}