This is an automated email from the ASF dual-hosted git repository.
agrove pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion-python.git
The following commit(s) were added to refs/heads/main by this push:
new 7a5f183 Add bindings for DropTable (#283)
7a5f183 is described below
commit 7a5f183d66ecba3a2deedcf76ee147980e84de4e
Author: Jeremy Dyer <[email protected]>
AuthorDate: Wed Mar 15 11:56:39 2023 -0400
Add bindings for DropTable (#283)
---
datafusion/__init__.py | 2 +
datafusion/tests/test_imports.py | 2 +
src/expr.rs | 2 +
src/expr/drop_table.rs | 89 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 95 insertions(+)
diff --git a/datafusion/__init__.py b/datafusion/__init__.py
index c9e58ec..e640c04 100644
--- a/datafusion/__init__.py
+++ b/datafusion/__init__.py
@@ -82,6 +82,7 @@ from .expr import (
Extension,
CreateView,
Distinct,
+ DropTable,
)
__version__ = importlib_metadata.version(__name__)
@@ -139,6 +140,7 @@ __all__ = [
"CreateMemoryTable",
"CreateView",
"Distinct",
+ "DropTable",
]
diff --git a/datafusion/tests/test_imports.py b/datafusion/tests/test_imports.py
index f46dd5e..eaa2302 100644
--- a/datafusion/tests/test_imports.py
+++ b/datafusion/tests/test_imports.py
@@ -83,6 +83,7 @@ from datafusion.expr import (
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 f277d02..579f509 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::<create_view::PyCreateView>()?;
m.add_class::<distinct::PyDistinct>()?;
m.add_class::<subquery_alias::PySubqueryAlias>()?;
+ m.add_class::<drop_table::PyDropTable>()?;
Ok(())
}
diff --git a/src/expr/drop_table.rs b/src/expr/drop_table.rs
new file mode 100644
index 0000000..2a8836d
--- /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<PyDropTable> for DropTable {
+ fn from(drop: PyDropTable) -> Self {
+ drop.drop
+ }
+}
+
+impl From<DropTable> 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<String> {
+ Ok(self.drop.name.to_string())
+ }
+
+ fn input(&self) -> PyResult<Vec<PyLogicalPlan>> {
+ Ok(Self::inputs(self))
+ }
+
+ fn if_exists(&self) -> bool {
+ self.drop.if_exists
+ }
+
+ fn __repr__(&self) -> PyResult<String> {
+ Ok(format!("DropTable({})", self))
+ }
+
+ fn __name__(&self) -> PyResult<String> {
+ Ok("DropTable".to_string())
+ }
+}
+
+impl LogicalNode for PyDropTable {
+ fn inputs(&self) -> Vec<PyLogicalPlan> {
+ vec![]
+ }
+
+ fn to_variant(&self, py: Python) -> PyResult<PyObject> {
+ Ok(self.clone().into_py(py))
+ }
+}