Skip to content

Commit bdcbb9f

Browse files
authored
Make expr member of PyExpr public (apache#375)
1 parent 6a2df77 commit bdcbb9f

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

src/common/data_type.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ use pyo3::prelude::*;
2121

2222
use crate::errors::py_datafusion_err;
2323

24+
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
25+
#[pyclass(name = "RexType", module = "datafusion.common")]
26+
pub enum RexType {
27+
Alias,
28+
Literal,
29+
Call,
30+
Reference,
31+
ScalarSubquery,
32+
Other,
33+
}
34+
2435
/// These bindings are tying together several disparate systems.
2536
/// You have SQL types for the SQL strings and RDBMS systems itself.
2637
/// Rust types for the DataFusion code

src/expr.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use datafusion::arrow::datatypes::DataType;
2222
use datafusion::arrow::pyarrow::PyArrowType;
2323
use datafusion_expr::{col, lit, Cast, Expr, GetIndexedField};
2424

25+
use crate::common::data_type::RexType;
2526
use crate::errors::py_runtime_err;
2627
use crate::expr::aggregate_expr::PyAggregateFunction;
2728
use crate::expr::binary_expr::PyBinaryExpr;
@@ -83,7 +84,7 @@ pub mod union;
8384
#[pyclass(name = "Expr", module = "datafusion.expr", subclass)]
8485
#[derive(Debug, Clone)]
8586
pub struct PyExpr {
86-
pub(crate) expr: Expr,
87+
pub expr: Expr,
8788
}
8889

8990
impl From<PyExpr> for Expr {
@@ -228,6 +229,51 @@ impl PyExpr {
228229
let expr = Expr::Cast(Cast::new(Box::new(self.expr.clone()), to.0));
229230
expr.into()
230231
}
232+
233+
/// A Rex (Row Expression) specifies a single row of data. That specification
234+
/// could include user defined functions or types. RexType identifies the row
235+
/// as one of the possible valid `RexTypes`.
236+
pub fn rex_type(&self) -> PyResult<RexType> {
237+
Ok(match self.expr {
238+
Expr::Alias(..) => RexType::Alias,
239+
Expr::Column(..) | Expr::QualifiedWildcard { .. } | Expr::GetIndexedField { .. } => {
240+
RexType::Reference
241+
}
242+
Expr::ScalarVariable(..) | Expr::Literal(..) => RexType::Literal,
243+
Expr::BinaryExpr { .. }
244+
| Expr::Not(..)
245+
| Expr::IsNotNull(..)
246+
| Expr::Negative(..)
247+
| Expr::IsNull(..)
248+
| Expr::Like { .. }
249+
| Expr::ILike { .. }
250+
| Expr::SimilarTo { .. }
251+
| Expr::Between { .. }
252+
| Expr::Case { .. }
253+
| Expr::Cast { .. }
254+
| Expr::TryCast { .. }
255+
| Expr::Sort { .. }
256+
| Expr::ScalarFunction { .. }
257+
| Expr::AggregateFunction { .. }
258+
| Expr::WindowFunction { .. }
259+
| Expr::AggregateUDF { .. }
260+
| Expr::InList { .. }
261+
| Expr::Wildcard
262+
| Expr::ScalarUDF { .. }
263+
| Expr::Exists { .. }
264+
| Expr::InSubquery { .. }
265+
| Expr::GroupingSet(..)
266+
| Expr::IsTrue(..)
267+
| Expr::IsFalse(..)
268+
| Expr::IsUnknown(_)
269+
| Expr::IsNotTrue(..)
270+
| Expr::IsNotFalse(..)
271+
| Expr::Placeholder { .. }
272+
| Expr::OuterReferenceColumn(_, _)
273+
| Expr::IsNotUnknown(_) => RexType::Call,
274+
Expr::ScalarSubquery(..) => RexType::ScalarSubquery,
275+
})
276+
}
231277
}
232278

233279
/// Initializes the `expr` module to match the pattern of `datafusion-expr` https://docs.rs/datafusion-expr/latest/datafusion_expr/

0 commit comments

Comments
 (0)