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 794d08a  add remaining expr bindings (#233)
794d08a is described below

commit 794d08af7c387c5ad9b6c3522f2eb972e99163f9
Author: Jeremy Dyer <[email protected]>
AuthorDate: Thu Feb 23 18:35:38 2023 -0500

    add remaining expr bindings (#233)
    
    * add remaining expr bindings
    
    * cargo fmt
    
    * cargo clippy
---
 datafusion/__init__.py           | 18 +++++++++++
 datafusion/tests/test_imports.py | 18 +++++++++++
 src/expr.rs                      | 18 +++++++++++
 src/expr/exists.rs               | 45 ++++++++++++++++++++++++++++
 src/expr/grouping_set.rs         | 37 +++++++++++++++++++++++
 src/expr/in_list.rs              | 53 ++++++++++++++++++++++++++++++++
 src/expr/in_subquery.rs          | 54 +++++++++++++++++++++++++++++++++
 src/expr/placeholder.rs          | 48 +++++++++++++++++++++++++++++
 src/expr/scalar_function.rs      | 65 ++++++++++++++++++++++++++++++++++++++++
 src/expr/scalar_subquery.rs      | 46 ++++++++++++++++++++++++++++
 src/expr/signature.rs            | 38 +++++++++++++++++++++++
 src/expr/subquery.rs             | 37 +++++++++++++++++++++++
 12 files changed, 477 insertions(+)

diff --git a/datafusion/__init__.py b/datafusion/__init__.py
index 3a6482d..f5583c2 100644
--- a/datafusion/__init__.py
+++ b/datafusion/__init__.py
@@ -63,6 +63,15 @@ from .expr import (
     IsNotFalse,
     IsNotUnknown,
     Negative,
+    ScalarFunction,
+    BuiltinScalarFunction,
+    InList,
+    Exists,
+    Subquery,
+    InSubquery,
+    ScalarSubquery,
+    GroupingSet,
+    Placeholder,
     Case,
     Cast,
     TryCast,
@@ -105,6 +114,15 @@ __all__ = [
     "IsNotFalse",
     "IsNotUnknown",
     "Negative",
+    "ScalarFunction",
+    "BuiltinScalarFunction",
+    "InList",
+    "Exists",
+    "Subquery",
+    "InSubquery",
+    "ScalarSubquery",
+    "GroupingSet",
+    "Placeholder",
     "Case",
     "Cast",
     "TryCast",
diff --git a/datafusion/tests/test_imports.py b/datafusion/tests/test_imports.py
index 3d4a0d9..20e7abb 100644
--- a/datafusion/tests/test_imports.py
+++ b/datafusion/tests/test_imports.py
@@ -59,6 +59,15 @@ from datafusion.expr import (
     IsNotFalse,
     IsNotUnknown,
     Negative,
+    ScalarFunction,
+    BuiltinScalarFunction,
+    InList,
+    Exists,
+    Subquery,
+    InSubquery,
+    ScalarSubquery,
+    GroupingSet,
+    Placeholder,
     Case,
     Cast,
     TryCast,
@@ -111,6 +120,15 @@ def test_class_module_is_datafusion():
         IsNotFalse,
         IsNotUnknown,
         Negative,
+        ScalarFunction,
+        BuiltinScalarFunction,
+        InList,
+        Exists,
+        Subquery,
+        InSubquery,
+        ScalarSubquery,
+        GroupingSet,
+        Placeholder,
         Case,
         Cast,
         TryCast,
diff --git a/src/expr.rs b/src/expr.rs
index 350eb66..a288b38 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -48,15 +48,24 @@ pub mod case;
 pub mod cast;
 pub mod column;
 pub mod empty_relation;
+pub mod exists;
 pub mod filter;
+pub mod grouping_set;
+pub mod in_list;
+pub mod in_subquery;
 pub mod indexed_field;
 pub mod like;
 pub mod limit;
 pub mod literal;
 pub mod logical_node;
+pub mod placeholder;
 pub mod projection;
+pub mod scalar_function;
+pub mod scalar_subquery;
 pub mod scalar_variable;
+pub mod signature;
 pub mod sort;
+pub mod subquery;
 pub mod table_scan;
 
 /// A PyExpr that can be used on a DataFrame
@@ -234,6 +243,15 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
     m.add_class::<PySimilarTo>()?;
     m.add_class::<PyScalarVariable>()?;
     m.add_class::<alias::PyAlias>()?;
+    m.add_class::<scalar_function::PyScalarFunction>()?;
+    m.add_class::<scalar_function::PyBuiltinScalarFunction>()?;
+    m.add_class::<in_list::PyInList>()?;
+    m.add_class::<exists::PyExists>()?;
+    m.add_class::<subquery::PySubquery>()?;
+    m.add_class::<in_subquery::PyInSubquery>()?;
+    m.add_class::<scalar_subquery::PyScalarSubquery>()?;
+    m.add_class::<placeholder::PyPlaceholder>()?;
+    m.add_class::<grouping_set::PyGroupingSet>()?;
     m.add_class::<case::PyCase>()?;
     m.add_class::<cast::PyCast>()?;
     m.add_class::<cast::PyTryCast>()?;
diff --git a/src/expr/exists.rs b/src/expr/exists.rs
new file mode 100644
index 0000000..7df9a6e
--- /dev/null
+++ b/src/expr/exists.rs
@@ -0,0 +1,45 @@
+// 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 datafusion_expr::Subquery;
+use pyo3::prelude::*;
+
+use super::subquery::PySubquery;
+
+#[pyclass(name = "Exists", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyExists {
+    subquery: Subquery,
+    negated: bool,
+}
+
+impl PyExists {
+    pub fn new(subquery: Subquery, negated: bool) -> Self {
+        Self { subquery, negated }
+    }
+}
+
+#[pymethods]
+impl PyExists {
+    fn subquery(&self) -> PySubquery {
+        self.subquery.clone().into()
+    }
+
+    fn negated(&self) -> bool {
+        self.negated
+    }
+}
diff --git a/src/expr/grouping_set.rs b/src/expr/grouping_set.rs
new file mode 100644
index 0000000..b739328
--- /dev/null
+++ b/src/expr/grouping_set.rs
@@ -0,0 +1,37 @@
+// 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 datafusion_expr::GroupingSet;
+use pyo3::prelude::*;
+
+#[pyclass(name = "GroupingSet", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyGroupingSet {
+    grouping_set: GroupingSet,
+}
+
+impl From<PyGroupingSet> for GroupingSet {
+    fn from(grouping_set: PyGroupingSet) -> Self {
+        grouping_set.grouping_set
+    }
+}
+
+impl From<GroupingSet> for PyGroupingSet {
+    fn from(grouping_set: GroupingSet) -> PyGroupingSet {
+        PyGroupingSet { grouping_set }
+    }
+}
diff --git a/src/expr/in_list.rs b/src/expr/in_list.rs
new file mode 100644
index 0000000..840eee2
--- /dev/null
+++ b/src/expr/in_list.rs
@@ -0,0 +1,53 @@
+// 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 crate::expr::PyExpr;
+use datafusion_expr::Expr;
+use pyo3::prelude::*;
+
+#[pyclass(name = "InList", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyInList {
+    expr: Box<Expr>,
+    list: Vec<Expr>,
+    negated: bool,
+}
+
+impl PyInList {
+    pub fn new(expr: Box<Expr>, list: Vec<Expr>, negated: bool) -> Self {
+        Self {
+            expr,
+            list,
+            negated,
+        }
+    }
+}
+
+#[pymethods]
+impl PyInList {
+    fn expr(&self) -> PyExpr {
+        (*self.expr).clone().into()
+    }
+
+    fn list(&self) -> Vec<PyExpr> {
+        self.list.iter().map(|e| e.clone().into()).collect()
+    }
+
+    fn negated(&self) -> bool {
+        self.negated
+    }
+}
diff --git a/src/expr/in_subquery.rs b/src/expr/in_subquery.rs
new file mode 100644
index 0000000..6cee4a1
--- /dev/null
+++ b/src/expr/in_subquery.rs
@@ -0,0 +1,54 @@
+// 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 datafusion_expr::{Expr, Subquery};
+use pyo3::prelude::*;
+
+use super::{subquery::PySubquery, PyExpr};
+
+#[pyclass(name = "InSubquery", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyInSubquery {
+    expr: Box<Expr>,
+    subquery: Subquery,
+    negated: bool,
+}
+
+impl PyInSubquery {
+    pub fn new(expr: Box<Expr>, subquery: Subquery, negated: bool) -> Self {
+        Self {
+            expr,
+            subquery,
+            negated,
+        }
+    }
+}
+
+#[pymethods]
+impl PyInSubquery {
+    fn expr(&self) -> PyExpr {
+        (*self.expr).clone().into()
+    }
+
+    fn subquery(&self) -> PySubquery {
+        self.subquery.clone().into()
+    }
+
+    fn negated(&self) -> bool {
+        self.negated
+    }
+}
diff --git a/src/expr/placeholder.rs b/src/expr/placeholder.rs
new file mode 100644
index 0000000..e37c8b5
--- /dev/null
+++ b/src/expr/placeholder.rs
@@ -0,0 +1,48 @@
+// 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 datafusion::arrow::datatypes::DataType;
+use pyo3::prelude::*;
+
+use crate::common::data_type::PyDataType;
+
+#[pyclass(name = "Placeholder", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyPlaceholder {
+    id: String,
+    data_type: Option<DataType>,
+}
+
+impl PyPlaceholder {
+    pub fn new(id: String, data_type: DataType) -> Self {
+        Self {
+            id,
+            data_type: Some(data_type),
+        }
+    }
+}
+
+#[pymethods]
+impl PyPlaceholder {
+    fn id(&self) -> String {
+        self.id.clone()
+    }
+
+    fn data_type(&self) -> Option<PyDataType> {
+        self.data_type.as_ref().map(|e| e.clone().into())
+    }
+}
diff --git a/src/expr/scalar_function.rs b/src/expr/scalar_function.rs
new file mode 100644
index 0000000..1a71d56
--- /dev/null
+++ b/src/expr/scalar_function.rs
@@ -0,0 +1,65 @@
+// 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 crate::expr::PyExpr;
+use datafusion_expr::{BuiltinScalarFunction, Expr};
+use pyo3::prelude::*;
+
+#[pyclass(name = "ScalarFunction", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyScalarFunction {
+    scalar_function: BuiltinScalarFunction,
+    args: Vec<Expr>,
+}
+
+impl PyScalarFunction {
+    pub fn new(scalar_function: BuiltinScalarFunction, args: Vec<Expr>) -> 
Self {
+        Self {
+            scalar_function,
+            args,
+        }
+    }
+}
+
+#[pyclass(name = "BuiltinScalarFunction", module = "datafusion.expr", 
subclass)]
+#[derive(Clone)]
+pub struct PyBuiltinScalarFunction {
+    scalar_function: BuiltinScalarFunction,
+}
+
+impl From<BuiltinScalarFunction> for PyBuiltinScalarFunction {
+    fn from(scalar_function: BuiltinScalarFunction) -> PyBuiltinScalarFunction 
{
+        PyBuiltinScalarFunction { scalar_function }
+    }
+}
+
+impl From<PyBuiltinScalarFunction> for BuiltinScalarFunction {
+    fn from(scalar_function: PyBuiltinScalarFunction) -> Self {
+        scalar_function.scalar_function
+    }
+}
+
+#[pymethods]
+impl PyScalarFunction {
+    fn fun(&self) -> PyResult<PyBuiltinScalarFunction> {
+        Ok(self.scalar_function.clone().into())
+    }
+
+    fn args(&self) -> PyResult<Vec<PyExpr>> {
+        Ok(self.args.iter().map(|e| e.clone().into()).collect())
+    }
+}
diff --git a/src/expr/scalar_subquery.rs b/src/expr/scalar_subquery.rs
new file mode 100644
index 0000000..c71bb99
--- /dev/null
+++ b/src/expr/scalar_subquery.rs
@@ -0,0 +1,46 @@
+// 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 datafusion_expr::Subquery;
+use pyo3::prelude::*;
+
+use super::subquery::PySubquery;
+
+#[pyclass(name = "ScalarSubquery", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PyScalarSubquery {
+    subquery: Subquery,
+}
+
+impl From<PyScalarSubquery> for Subquery {
+    fn from(subquery: PyScalarSubquery) -> Self {
+        subquery.subquery
+    }
+}
+
+impl From<Subquery> for PyScalarSubquery {
+    fn from(subquery: Subquery) -> PyScalarSubquery {
+        PyScalarSubquery { subquery }
+    }
+}
+
+#[pymethods]
+impl PyScalarSubquery {
+    fn subquery(&self) -> PySubquery {
+        self.subquery.clone().into()
+    }
+}
diff --git a/src/expr/signature.rs b/src/expr/signature.rs
new file mode 100644
index 0000000..c59c990
--- /dev/null
+++ b/src/expr/signature.rs
@@ -0,0 +1,38 @@
+// 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 datafusion_expr::{TypeSignature, Volatility};
+use pyo3::prelude::*;
+
+#[pyclass(name = "Signature", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PySignature {
+    type_signature: TypeSignature,
+    volatility: Volatility,
+}
+
+impl PySignature {
+    pub fn new(type_signature: TypeSignature, volatility: Volatility) -> Self {
+        Self {
+            type_signature,
+            volatility,
+        }
+    }
+}
+
+#[pymethods]
+impl PySignature {}
diff --git a/src/expr/subquery.rs b/src/expr/subquery.rs
new file mode 100644
index 0000000..93ff244
--- /dev/null
+++ b/src/expr/subquery.rs
@@ -0,0 +1,37 @@
+// 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 datafusion_expr::Subquery;
+use pyo3::prelude::*;
+
+#[pyclass(name = "Subquery", module = "datafusion.expr", subclass)]
+#[derive(Clone)]
+pub struct PySubquery {
+    subquery: Subquery,
+}
+
+impl From<PySubquery> for Subquery {
+    fn from(subquery: PySubquery) -> Self {
+        subquery.subquery
+    }
+}
+
+impl From<Subquery> for PySubquery {
+    fn from(subquery: Subquery) -> PySubquery {
+        PySubquery { subquery }
+    }
+}

Reply via email to