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