File tree 3 files changed +17
-1
lines changed
3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -1266,7 +1266,7 @@ impl Expr {
1266
1266
pub fn short_circuits ( & self ) -> bool {
1267
1267
match self {
1268
1268
Expr :: ScalarFunction ( ScalarFunction { func_def, .. } ) => {
1269
- matches ! ( func_def, ScalarFunctionDefinition :: UDF ( fun) if fun. name ( ) . eq ( "coalesce" ) )
1269
+ matches ! ( func_def, ScalarFunctionDefinition :: UDF ( fun) if fun. short_circuits ( ) )
1270
1270
}
1271
1271
Expr :: BinaryExpr ( BinaryExpr { op, .. } ) => {
1272
1272
matches ! ( op, Operator :: And | Operator :: Or )
Original file line number Diff line number Diff line change @@ -193,6 +193,11 @@ impl ScalarUDF {
193
193
pub fn monotonicity ( & self ) -> Result < Option < FuncMonotonicity > > {
194
194
self . inner . monotonicity ( )
195
195
}
196
+
197
+ /// Get the circuits of inner implementation
198
+ pub fn short_circuits ( & self ) -> bool {
199
+ self . inner . short_circuits ( )
200
+ }
196
201
}
197
202
198
203
impl < F > From < F > for ScalarUDF
@@ -376,6 +381,13 @@ pub trait ScalarUDFImpl: Debug + Send + Sync {
376
381
) -> Result < ExprSimplifyResult > {
377
382
Ok ( ExprSimplifyResult :: Original ( args) )
378
383
}
384
+
385
+ /// Returns true if some of this `exprs` subexpressions may not be evaluated
386
+ /// and thus any side effects (like divide by zero) may not be encountered
387
+ /// Setting this to true prevents certain optimizations such as common subexpression elimination
388
+ fn short_circuits ( & self ) -> bool {
389
+ false
390
+ }
379
391
}
380
392
381
393
/// ScalarUDF that adds an alias to the underlying function. It is better to
Original file line number Diff line number Diff line change @@ -120,6 +120,10 @@ impl ScalarUDFImpl for CoalesceFunc {
120
120
Ok ( result)
121
121
}
122
122
}
123
+
124
+ fn short_circuits ( & self ) -> bool {
125
+ true
126
+ }
123
127
}
124
128
125
129
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments