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 bdcbb9f Make expr member of PyExpr public (#375)
bdcbb9f is described below
commit bdcbb9f12e59ee863c418fdf21f64182aab66b11
Author: Jeremy Dyer <[email protected]>
AuthorDate: Tue May 9 08:39:50 2023 -0400
Make expr member of PyExpr public (#375)
---
src/common/data_type.rs | 11 +++++++++++
src/expr.rs | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/src/common/data_type.rs b/src/common/data_type.rs
index a9b0d17..d55a0e8 100644
--- a/src/common/data_type.rs
+++ b/src/common/data_type.rs
@@ -21,6 +21,17 @@ use pyo3::prelude::*;
use crate::errors::py_datafusion_err;
+#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
+#[pyclass(name = "RexType", module = "datafusion.common")]
+pub enum RexType {
+ Alias,
+ Literal,
+ Call,
+ Reference,
+ ScalarSubquery,
+ Other,
+}
+
/// These bindings are tying together several disparate systems.
/// You have SQL types for the SQL strings and RDBMS systems itself.
/// Rust types for the DataFusion code
diff --git a/src/expr.rs b/src/expr.rs
index 7c80d0d..4ada4c1 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -22,6 +22,7 @@ use datafusion::arrow::datatypes::DataType;
use datafusion::arrow::pyarrow::PyArrowType;
use datafusion_expr::{col, lit, Cast, Expr, GetIndexedField};
+use crate::common::data_type::RexType;
use crate::errors::py_runtime_err;
use crate::expr::aggregate_expr::PyAggregateFunction;
use crate::expr::binary_expr::PyBinaryExpr;
@@ -83,7 +84,7 @@ pub mod union;
#[pyclass(name = "Expr", module = "datafusion.expr", subclass)]
#[derive(Debug, Clone)]
pub struct PyExpr {
- pub(crate) expr: Expr,
+ pub expr: Expr,
}
impl From<PyExpr> for Expr {
@@ -228,6 +229,51 @@ impl PyExpr {
let expr = Expr::Cast(Cast::new(Box::new(self.expr.clone()), to.0));
expr.into()
}
+
+ /// A Rex (Row Expression) specifies a single row of data. That
specification
+ /// could include user defined functions or types. RexType identifies the
row
+ /// as one of the possible valid `RexTypes`.
+ pub fn rex_type(&self) -> PyResult<RexType> {
+ Ok(match self.expr {
+ Expr::Alias(..) => RexType::Alias,
+ Expr::Column(..) | Expr::QualifiedWildcard { .. } |
Expr::GetIndexedField { .. } => {
+ RexType::Reference
+ }
+ Expr::ScalarVariable(..) | Expr::Literal(..) => RexType::Literal,
+ Expr::BinaryExpr { .. }
+ | Expr::Not(..)
+ | Expr::IsNotNull(..)
+ | Expr::Negative(..)
+ | Expr::IsNull(..)
+ | Expr::Like { .. }
+ | Expr::ILike { .. }
+ | Expr::SimilarTo { .. }
+ | Expr::Between { .. }
+ | Expr::Case { .. }
+ | Expr::Cast { .. }
+ | Expr::TryCast { .. }
+ | Expr::Sort { .. }
+ | Expr::ScalarFunction { .. }
+ | Expr::AggregateFunction { .. }
+ | Expr::WindowFunction { .. }
+ | Expr::AggregateUDF { .. }
+ | Expr::InList { .. }
+ | Expr::Wildcard
+ | Expr::ScalarUDF { .. }
+ | Expr::Exists { .. }
+ | Expr::InSubquery { .. }
+ | Expr::GroupingSet(..)
+ | Expr::IsTrue(..)
+ | Expr::IsFalse(..)
+ | Expr::IsUnknown(_)
+ | Expr::IsNotTrue(..)
+ | Expr::IsNotFalse(..)
+ | Expr::Placeholder { .. }
+ | Expr::OuterReferenceColumn(_, _)
+ | Expr::IsNotUnknown(_) => RexType::Call,
+ Expr::ScalarSubquery(..) => RexType::ScalarSubquery,
+ })
+ }
}
/// Initializes the `expr` module to match the pattern of `datafusion-expr`
https://docs.rs/datafusion-expr/latest/datafusion_expr/