1
1
use super :: * ;
2
+ use crate :: plans:: conversion:: functions:: convert_functions;
2
3
3
4
pub fn to_expr_ir ( expr : Expr , arena : & mut Arena < AExpr > ) -> PolarsResult < ExprIR > {
4
5
let mut state = ConversionContext :: new ( ) ;
@@ -40,12 +41,12 @@ pub fn to_aexpr(expr: Expr, arena: &mut Arena<AExpr>) -> PolarsResult<Node> {
40
41
}
41
42
42
43
#[ derive( Default ) ]
43
- struct ConversionContext {
44
- output_name : OutputName ,
44
+ pub ( super ) struct ConversionContext {
45
+ pub ( super ) output_name : OutputName ,
45
46
/// Remove alias from the expressions and set as [`OutputName`].
46
- prune_alias : bool ,
47
+ pub ( super ) prune_alias : bool ,
47
48
/// If an `alias` is encountered prune and ignore it.
48
- ignore_alias : bool ,
49
+ pub ( super ) ignore_alias : bool ,
49
50
}
50
51
51
52
impl ConversionContext {
@@ -68,14 +69,17 @@ fn to_aexprs(
68
69
. collect ( )
69
70
}
70
71
71
- fn set_function_output_name < F > ( e : & [ ExprIR ] , state : & mut ConversionContext , function_fmt : F )
72
- where
73
- F : FnOnce ( ) -> Cow < ' static , str > ,
72
+ pub ( super ) fn set_function_output_name < F > (
73
+ e : & [ ExprIR ] ,
74
+ state : & mut ConversionContext ,
75
+ function_fmt : F ,
76
+ ) where
77
+ F : FnOnce ( ) -> PlSmallStr ,
74
78
{
75
79
if state. output_name . is_none ( ) {
76
80
if e. is_empty ( ) {
77
81
let s = function_fmt ( ) ;
78
- state. output_name = OutputName :: LiteralLhs ( PlSmallStr :: from_str ( s . as_ref ( ) ) ) ;
82
+ state. output_name = OutputName :: LiteralLhs ( s ) ;
79
83
} else {
80
84
state. output_name = e[ 0 ] . output_name_inner ( ) . clone ( ) ;
81
85
}
@@ -117,7 +121,7 @@ fn to_aexpr_impl_materialized_lit(
117
121
118
122
/// Converts expression to AExpr and adds it to the arena, which uses an arena (Vec) for allocation.
119
123
#[ recursive]
120
- fn to_aexpr_impl (
124
+ pub ( super ) fn to_aexpr_impl (
121
125
expr : Expr ,
122
126
arena : & mut Arena < AExpr > ,
123
127
state : & mut ConversionContext ,
@@ -281,7 +285,7 @@ fn to_aexpr_impl(
281
285
options,
282
286
} => {
283
287
let e = to_expr_irs ( input, arena) ?;
284
- set_function_output_name ( & e, state, || Cow :: Borrowed ( options. fmt_str ) ) ;
288
+ set_function_output_name ( & e, state, || PlSmallStr :: from_static ( options. fmt_str ) ) ;
285
289
AExpr :: AnonymousFunction {
286
290
input : e,
287
291
function,
@@ -293,55 +297,7 @@ fn to_aexpr_impl(
293
297
input,
294
298
function,
295
299
options,
296
- } => {
297
- match function {
298
- // This can be created by col(*).is_null() on empty dataframes.
299
- FunctionExpr :: Boolean (
300
- BooleanFunction :: AllHorizontal | BooleanFunction :: AnyHorizontal ,
301
- ) if input. is_empty ( ) => {
302
- return to_aexpr_impl ( lit ( true ) , arena, state) ;
303
- } ,
304
- // Convert to binary expression as the optimizer understands those.
305
- // Don't exceed 128 expressions as we might stackoverflow.
306
- FunctionExpr :: Boolean ( BooleanFunction :: AllHorizontal ) => {
307
- if input. len ( ) < 128 {
308
- let expr = input
309
- . into_iter ( )
310
- . reduce ( |l, r| l. logical_and ( r) )
311
- . unwrap ( )
312
- . cast ( DataType :: Boolean ) ;
313
- return to_aexpr_impl ( expr, arena, state) ;
314
- }
315
- } ,
316
- FunctionExpr :: Boolean ( BooleanFunction :: AnyHorizontal ) => {
317
- if input. len ( ) < 128 {
318
- let expr = input
319
- . into_iter ( )
320
- . reduce ( |l, r| l. logical_or ( r) )
321
- . unwrap ( )
322
- . cast ( DataType :: Boolean ) ;
323
- return to_aexpr_impl ( expr, arena, state) ;
324
- }
325
- } ,
326
- _ => { } ,
327
- }
328
-
329
- let e = to_expr_irs ( input, arena) ?;
330
-
331
- if state. output_name . is_none ( ) {
332
- // Handles special case functions like `struct.field`.
333
- if let Some ( name) = function. output_name ( ) {
334
- state. output_name = name
335
- } else {
336
- set_function_output_name ( & e, state, || Cow :: Owned ( format ! ( "{}" , & function) ) ) ;
337
- }
338
- }
339
- AExpr :: Function {
340
- input : e,
341
- function,
342
- options,
343
- }
344
- } ,
300
+ } => return convert_functions ( input, function, options, arena, state) ,
345
301
Expr :: Window {
346
302
function,
347
303
partition_by,
0 commit comments