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 fad9a3f  Distinct bindings (#275)
fad9a3f is described below

commit fad9a3fe03d8a68b96414ce530a33e787bac944e
Author: Jeremy Dyer <[email protected]>
AuthorDate: Mon Mar 13 20:02:10 2023 -0400

    Distinct bindings (#275)
---
 datafusion/__init__.py           |  2 +
 datafusion/tests/test_imports.py |  2 +
 src/expr.rs                      |  2 +
 src/expr/distinct.rs             | 80 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+)

diff --git a/datafusion/__init__.py b/datafusion/__init__.py
index c3b76d2..c9e58ec 100644
--- a/datafusion/__init__.py
+++ b/datafusion/__init__.py
@@ -81,6 +81,7 @@ from .expr import (
     SubqueryAlias,
     Extension,
     CreateView,
+    Distinct,
 )
 
 __version__ = importlib_metadata.version(__name__)
@@ -137,6 +138,7 @@ __all__ = [
     "Extension",
     "CreateMemoryTable",
     "CreateView",
+    "Distinct",
 ]
 
 
diff --git a/datafusion/tests/test_imports.py b/datafusion/tests/test_imports.py
index ed9f710..f46dd5e 100644
--- a/datafusion/tests/test_imports.py
+++ b/datafusion/tests/test_imports.py
@@ -82,6 +82,7 @@ from datafusion.expr import (
     Extension,
     CreateMemoryTable,
     CreateView,
+    Distinct,
 )
 
 
@@ -153,6 +154,7 @@ def test_class_module_is_datafusion():
         Extension,
         CreateMemoryTable,
         CreateView,
+        Distinct,
     ]:
         assert klass.__module__ == "datafusion.expr"
 
diff --git a/src/expr.rs b/src/expr.rs
index 71a6c0b..f277d02 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -50,6 +50,7 @@ pub mod column;
 pub mod create_memory_table;
 pub mod create_view;
 pub mod cross_join;
+pub mod distinct;
 pub mod empty_relation;
 pub mod exists;
 pub mod explain;
@@ -282,6 +283,7 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
     m.add_class::<table_scan::PyTableScan>()?;
     m.add_class::<create_memory_table::PyCreateMemoryTable>()?;
     m.add_class::<create_view::PyCreateView>()?;
+    m.add_class::<distinct::PyDistinct>()?;
     m.add_class::<subquery_alias::PySubqueryAlias>()?;
     Ok(())
 }
diff --git a/src/expr/distinct.rs b/src/expr/distinct.rs
new file mode 100644
index 0000000..681ae95
--- /dev/null
+++ b/src/expr/distinct.rs
@@ -0,0 +1,80 @@
+// 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::Distinct;
+use pyo3::prelude::*;
+
+use crate::sql::logical::PyLogicalPlan;
+
+use super::logical_node::LogicalNode;
+
+#[pyclass(name = "Distinct", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyDistinct {
+    distinct: Distinct,
+}
+
+impl From<PyDistinct> for Distinct {
+    fn from(distinct: PyDistinct) -> Self {
+        distinct.distinct
+    }
+}
+
+impl From<Distinct> for PyDistinct {
+    fn from(distinct: Distinct) -> PyDistinct {
+        PyDistinct { distinct }
+    }
+}
+
+impl Display for PyDistinct {
+    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+        write!(
+            f,
+            "Distinct
+            \nInput: {:?}",
+            self.distinct.input,
+        )
+    }
+}
+
+#[pymethods]
+impl PyDistinct {
+    /// Retrieves the input `LogicalPlan` to this `Projection` node
+    fn input(&self) -> PyResult<Vec<PyLogicalPlan>> {
+        Ok(Self::inputs(self))
+    }
+
+    fn __repr__(&self) -> PyResult<String> {
+        Ok(format!("Distinct({})", self))
+    }
+
+    fn __name__(&self) -> PyResult<String> {
+        Ok("Distinct".to_string())
+    }
+}
+
+impl LogicalNode for PyDistinct {
+    fn inputs(&self) -> Vec<PyLogicalPlan> {
+        vec![PyLogicalPlan::from((*self.distinct.input).clone())]
+    }
+
+    fn to_variant(&self, py: Python) -> PyResult<PyObject> {
+        Ok(self.clone().into_py(py))
+    }
+}

Reply via email to