Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add remaining expr bindings #233

Merged
merged 4 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions datafusion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@
IsNotFalse,
IsNotUnknown,
Negative,
ScalarFunction,
BuiltinScalarFunction,
InList,
Exists,
Subquery,
InSubquery,
ScalarSubquery,
GroupingSet,
Placeholder,
)

__version__ = importlib_metadata.version(__name__)
Expand Down Expand Up @@ -99,6 +108,15 @@
"IsNotFalse",
"IsNotUnknown",
"Negative",
"ScalarFunction",
"BuiltinScalarFunction",
"InList",
"Exists",
"Subquery",
"InSubquery",
"ScalarSubquery",
"GroupingSet",
"Placeholder",
]


Expand Down
18 changes: 18 additions & 0 deletions datafusion/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@
IsNotFalse,
IsNotUnknown,
Negative,
ScalarFunction,
BuiltinScalarFunction,
InList,
Exists,
Subquery,
InSubquery,
ScalarSubquery,
GroupingSet,
Placeholder,
)


Expand Down Expand Up @@ -105,6 +114,15 @@ def test_class_module_is_datafusion():
IsNotFalse,
IsNotUnknown,
Negative,
ScalarFunction,
BuiltinScalarFunction,
InList,
Exists,
Subquery,
InSubquery,
ScalarSubquery,
GroupingSet,
Placeholder,
]:
assert klass.__module__ == "datafusion.expr"

Expand Down
18 changes: 18 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ pub mod projection;
pub mod scalar_variable;
pub mod sort;
pub mod table_scan;
pub mod scalar_function;
pub mod signature;
pub mod in_list;
pub mod exists;
pub mod in_subquery;
pub mod subquery;
pub mod scalar_subquery;
pub mod grouping_set;
pub mod placeholder;

/// A PyExpr that can be used on a DataFrame
#[pyclass(name = "Expr", module = "datafusion.expr", subclass)]
Expand Down Expand Up @@ -230,6 +239,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>()?;
// operators
m.add_class::<table_scan::PyTableScan>()?;
m.add_class::<projection::PyProjection>()?;
Expand Down
48 changes: 48 additions & 0 deletions src/expr/exists.rs
Original file line number Diff line number Diff line change
@@ -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_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
}
}
37 changes: 37 additions & 0 deletions src/expr/grouping_set.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
}
56 changes: 56 additions & 0 deletions src/expr/in_list.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// 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
}
}
54 changes: 54 additions & 0 deletions src/expr/in_subquery.rs
Original file line number Diff line number Diff line change
@@ -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::{Subquery, Expr};
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
}
}
Loading