diff --git a/datafusion/__init__.py b/datafusion/__init__.py index c9e58ec7a..e640c041f 100644 --- a/datafusion/__init__.py +++ b/datafusion/__init__.py @@ -82,6 +82,7 @@ Extension, CreateView, Distinct, + DropTable, ) __version__ = importlib_metadata.version(__name__) @@ -139,6 +140,7 @@ "CreateMemoryTable", "CreateView", "Distinct", + "DropTable", ] diff --git a/datafusion/tests/test_imports.py b/datafusion/tests/test_imports.py index f46dd5e4f..eaa230221 100644 --- a/datafusion/tests/test_imports.py +++ b/datafusion/tests/test_imports.py @@ -83,6 +83,7 @@ CreateMemoryTable, CreateView, Distinct, + DropTable, ) @@ -155,6 +156,7 @@ def test_class_module_is_datafusion(): CreateMemoryTable, CreateView, Distinct, + DropTable, ]: assert klass.__module__ == "datafusion.expr" diff --git a/src/expr.rs b/src/expr.rs index f277d0266..579f5098d 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -51,6 +51,7 @@ pub mod create_memory_table; pub mod create_view; pub mod cross_join; pub mod distinct; +pub mod drop_table; pub mod empty_relation; pub mod exists; pub mod explain; @@ -285,5 +286,6 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; Ok(()) } diff --git a/src/expr/drop_table.rs b/src/expr/drop_table.rs new file mode 100644 index 000000000..2a8836db5 --- /dev/null +++ b/src/expr/drop_table.rs @@ -0,0 +1,89 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +use std::fmt::{self, Display, Formatter}; + +use datafusion_expr::logical_plan::DropTable; +use pyo3::prelude::*; + +use crate::sql::logical::PyLogicalPlan; + +use super::logical_node::LogicalNode; + +#[pyclass(name = "DropTable", module = "datafusion.expr", subclass)] +#[derive(Clone)] +pub struct PyDropTable { + drop: DropTable, +} + +impl From for DropTable { + fn from(drop: PyDropTable) -> Self { + drop.drop + } +} + +impl From for PyDropTable { + fn from(drop: DropTable) -> PyDropTable { + PyDropTable { drop } + } +} + +impl Display for PyDropTable { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!( + f, + "DropTable + name: {:?} + if_exists: {:?} + schema: {:?}", + &self.drop.name, &self.drop.if_exists, &self.drop.schema, + ) + } +} + +#[pymethods] +impl PyDropTable { + fn name(&self) -> PyResult { + Ok(self.drop.name.to_string()) + } + + fn input(&self) -> PyResult> { + Ok(Self::inputs(self)) + } + + fn if_exists(&self) -> bool { + self.drop.if_exists + } + + fn __repr__(&self) -> PyResult { + Ok(format!("DropTable({})", self)) + } + + fn __name__(&self) -> PyResult { + Ok("DropTable".to_string()) + } +} + +impl LogicalNode for PyDropTable { + fn inputs(&self) -> Vec { + vec![] + } + + fn to_variant(&self, py: Python) -> PyResult { + Ok(self.clone().into_py(py)) + } +}