@@ -22,6 +22,7 @@ use datafusion::arrow::datatypes::DataType;
2222use datafusion:: arrow:: pyarrow:: PyArrowType ;
2323use datafusion_expr:: { col, lit, Cast , Expr , GetIndexedField } ;
2424
25+ use crate :: common:: data_type:: RexType ;
2526use crate :: errors:: py_runtime_err;
2627use crate :: expr:: aggregate_expr:: PyAggregateFunction ;
2728use crate :: expr:: binary_expr:: PyBinaryExpr ;
@@ -83,7 +84,7 @@ pub mod union;
8384#[ pyclass( name = "Expr" , module = "datafusion.expr" , subclass) ]
8485#[ derive( Debug , Clone ) ]
8586pub struct PyExpr {
86- pub ( crate ) expr : Expr ,
87+ pub expr : Expr ,
8788}
8889
8990impl 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