datafusion_python/expr/
unnest.rs1use datafusion::logical_expr::logical_plan::Unnest;
19use pyo3::{prelude::*, IntoPyObjectExt};
20use std::fmt::{self, Display, Formatter};
21
22use crate::common::df_schema::PyDFSchema;
23use crate::expr::logical_node::LogicalNode;
24use crate::sql::logical::PyLogicalPlan;
25
26#[pyclass(name = "Unnest", module = "datafusion.expr", subclass)]
27#[derive(Clone)]
28pub struct PyUnnest {
29 unnest_: Unnest,
30}
31
32impl From<Unnest> for PyUnnest {
33 fn from(unnest_: Unnest) -> PyUnnest {
34 PyUnnest { unnest_ }
35 }
36}
37
38impl From<PyUnnest> for Unnest {
39 fn from(unnest_: PyUnnest) -> Self {
40 unnest_.unnest_
41 }
42}
43
44impl Display for PyUnnest {
45 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
46 write!(
47 f,
48 "Unnest
49 Inputs: {:?}
50 Schema: {:?}",
51 &self.unnest_.input, &self.unnest_.schema,
52 )
53 }
54}
55
56#[pymethods]
57impl PyUnnest {
58 fn input(&self) -> PyResult<Vec<PyLogicalPlan>> {
60 Ok(Self::inputs(self))
61 }
62
63 fn schema(&self) -> PyResult<PyDFSchema> {
65 Ok(self.unnest_.schema.as_ref().clone().into())
66 }
67
68 fn __repr__(&self) -> PyResult<String> {
69 Ok(format!("Unnest({})", self))
70 }
71
72 fn __name__(&self) -> PyResult<String> {
73 Ok("Unnest".to_string())
74 }
75}
76
77impl LogicalNode for PyUnnest {
78 fn inputs(&self) -> Vec<PyLogicalPlan> {
79 vec![PyLogicalPlan::from((*self.unnest_.input).clone())]
80 }
81
82 fn to_variant<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
83 self.clone().into_bound_py_any(py)
84 }
85}