diff --git a/src/expr.rs b/src/expr.rs index 657192e6..f2209b90 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -90,6 +90,7 @@ pub mod subquery_alias; pub mod table_scan; pub mod union; pub mod unnest; +pub mod unnest_expr; pub mod window; /// A PyExpr that can be used on a DataFrame @@ -169,7 +170,7 @@ impl PyExpr { Ok(placeholder::PyPlaceholder::from(value.clone()).into_py(py)) } Expr::OuterReferenceColumn(_, _) => todo!(), - Expr::Unnest(_) => todo!(), + Expr::Unnest(value) => Ok(unnest_expr::PyUnnestExpr::from(value.clone()).into_py(py)), }) } @@ -624,6 +625,7 @@ pub(crate) fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; diff --git a/src/expr/unnest_expr.rs b/src/expr/unnest_expr.rs new file mode 100644 index 00000000..a2f8230c --- /dev/null +++ b/src/expr/unnest_expr.rs @@ -0,0 +1,67 @@ +// 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::Unnest; +use pyo3::prelude::*; +use std::fmt::{self, Display, Formatter}; + +use super::PyExpr; + +#[pyclass(name = "UnnestExpr", module = "datafusion.expr", subclass)] +#[derive(Clone)] +pub struct PyUnnestExpr { + unnest: Unnest, +} + +impl From for PyUnnestExpr { + fn from(unnest: Unnest) -> PyUnnestExpr { + PyUnnestExpr { unnest } + } +} + +impl From for Unnest { + fn from(unnest: PyUnnestExpr) -> Self { + unnest.unnest + } +} + +impl Display for PyUnnestExpr { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + write!( + f, + "Unnest + Expr: {:?}", + &self.unnest.expr, + ) + } +} + +#[pymethods] +impl PyUnnestExpr { + /// Retrieves the expression that is being unnested + fn expr(&self) -> PyResult { + Ok((*self.unnest.expr).clone().into()) + } + + fn __repr__(&self) -> PyResult { + Ok(format!("UnnestExpr({})", self)) + } + + fn __name__(&self) -> PyResult { + Ok("UnnestExpr".to_string()) + } +}