@@ -33,7 +33,7 @@ use datafusion_expr::{
3333} ;
3434
3535use crate :: common:: data_type:: { DataTypeMap , RexType } ;
36- use crate :: errors:: { py_runtime_err, py_type_err, DataFusionError } ;
36+ use crate :: errors:: { py_runtime_err, py_type_err, py_unsupported_variant_err , DataFusionError } ;
3737use crate :: expr:: aggregate_expr:: PyAggregateFunction ;
3838use crate :: expr:: binary_expr:: PyBinaryExpr ;
3939use crate :: expr:: column:: PyColumn ;
@@ -84,11 +84,13 @@ pub mod scalar_subquery;
8484pub mod scalar_variable;
8585pub mod signature;
8686pub mod sort;
87+ pub mod sort_expr;
8788pub mod subquery;
8889pub mod subquery_alias;
8990pub mod table_scan;
9091pub mod union;
9192pub mod unnest;
93+ pub mod unnest_expr;
9294pub mod window;
9395
9496/// A PyExpr that can be used on a DataFrame
@@ -119,8 +121,9 @@ pub fn py_expr_list(expr: &[Expr]) -> PyResult<Vec<PyExpr>> {
119121impl PyExpr {
120122 /// Return the specific expression
121123 fn to_variant ( & self , py : Python ) -> PyResult < PyObject > {
122- Python :: with_gil ( |_| match & self . expr {
123- Expr :: Alias ( alias) => Ok ( PyAlias :: new ( & alias. expr , & alias. name ) . into_py ( py) ) ,
124+ Python :: with_gil ( |_| {
125+ match & self . expr {
126+ Expr :: Alias ( alias) => Ok ( PyAlias :: from ( alias. clone ( ) ) . into_py ( py) ) ,
124127 Expr :: Column ( col) => Ok ( PyColumn :: from ( col. clone ( ) ) . into_py ( py) ) ,
125128 Expr :: ScalarVariable ( data_type, variables) => {
126129 Ok ( PyScalarVariable :: new ( data_type, variables) . into_py ( py) )
@@ -141,10 +144,44 @@ impl PyExpr {
141144 Expr :: AggregateFunction ( expr) => {
142145 Ok ( PyAggregateFunction :: from ( expr. clone ( ) ) . into_py ( py) )
143146 }
144- other => Err ( py_runtime_err ( format ! (
145- "Cannot convert this Expr to a Python object: {:?}" ,
146- other
147+ Expr :: SimilarTo ( value) => Ok ( PySimilarTo :: from ( value. clone ( ) ) . into_py ( py) ) ,
148+ Expr :: Between ( value) => Ok ( between:: PyBetween :: from ( value. clone ( ) ) . into_py ( py) ) ,
149+ Expr :: Case ( value) => Ok ( case:: PyCase :: from ( value. clone ( ) ) . into_py ( py) ) ,
150+ Expr :: Cast ( value) => Ok ( cast:: PyCast :: from ( value. clone ( ) ) . into_py ( py) ) ,
151+ Expr :: TryCast ( value) => Ok ( cast:: PyTryCast :: from ( value. clone ( ) ) . into_py ( py) ) ,
152+ Expr :: Sort ( value) => Ok ( sort_expr:: PySortExpr :: from ( value. clone ( ) ) . into_py ( py) ) ,
153+ Expr :: ScalarFunction ( value) => Err ( py_unsupported_variant_err ( format ! (
154+ "Converting Expr::ScalarFunction to a Python object is not implemented: {:?}" ,
155+ value
147156 ) ) ) ,
157+ Expr :: WindowFunction ( value) => Err ( py_unsupported_variant_err ( format ! (
158+ "Converting Expr::WindowFunction to a Python object is not implemented: {:?}" ,
159+ value
160+ ) ) ) ,
161+ Expr :: InList ( value) => Ok ( in_list:: PyInList :: from ( value. clone ( ) ) . into_py ( py) ) ,
162+ Expr :: Exists ( value) => Ok ( exists:: PyExists :: from ( value. clone ( ) ) . into_py ( py) ) ,
163+ Expr :: InSubquery ( value) => {
164+ Ok ( in_subquery:: PyInSubquery :: from ( value. clone ( ) ) . into_py ( py) )
165+ }
166+ Expr :: ScalarSubquery ( value) => {
167+ Ok ( scalar_subquery:: PyScalarSubquery :: from ( value. clone ( ) ) . into_py ( py) )
168+ }
169+ Expr :: Wildcard { qualifier } => Err ( py_unsupported_variant_err ( format ! (
170+ "Converting Expr::Wildcard to a Python object is not implemented : {:?}" ,
171+ qualifier
172+ ) ) ) ,
173+ Expr :: GroupingSet ( value) => {
174+ Ok ( grouping_set:: PyGroupingSet :: from ( value. clone ( ) ) . into_py ( py) )
175+ }
176+ Expr :: Placeholder ( value) => {
177+ Ok ( placeholder:: PyPlaceholder :: from ( value. clone ( ) ) . into_py ( py) )
178+ }
179+ Expr :: OuterReferenceColumn ( data_type, column) => Err ( py_unsupported_variant_err ( format ! (
180+ "Converting Expr::OuterReferenceColumn to a Python object is not implemented: {:?} - {:?}" ,
181+ data_type, column
182+ ) ) ) ,
183+ Expr :: Unnest ( value) => Ok ( unnest_expr:: PyUnnestExpr :: from ( value. clone ( ) ) . into_py ( py) ) ,
184+ }
148185 } )
149186 }
150187
@@ -599,13 +636,15 @@ pub(crate) fn init_module(m: &Bound<'_, PyModule>) -> PyResult<()> {
599636 m. add_class :: < cross_join:: PyCrossJoin > ( ) ?;
600637 m. add_class :: < union:: PyUnion > ( ) ?;
601638 m. add_class :: < unnest:: PyUnnest > ( ) ?;
639+ m. add_class :: < unnest_expr:: PyUnnestExpr > ( ) ?;
602640 m. add_class :: < extension:: PyExtension > ( ) ?;
603641 m. add_class :: < filter:: PyFilter > ( ) ?;
604642 m. add_class :: < projection:: PyProjection > ( ) ?;
605643 m. add_class :: < table_scan:: PyTableScan > ( ) ?;
606644 m. add_class :: < create_memory_table:: PyCreateMemoryTable > ( ) ?;
607645 m. add_class :: < create_view:: PyCreateView > ( ) ?;
608646 m. add_class :: < distinct:: PyDistinct > ( ) ?;
647+ m. add_class :: < sort_expr:: PySortExpr > ( ) ?;
609648 m. add_class :: < subquery_alias:: PySubqueryAlias > ( ) ?;
610649 m. add_class :: < drop_table:: PyDropTable > ( ) ?;
611650 m. add_class :: < repartition:: PyPartitioning > ( ) ?;
0 commit comments