MCPcopy Create free account
hub / github.com/apache/datafusion / rewrite_binary_expr

Function rewrite_binary_expr

datafusion/expr/src/expr_rewriter/guarantees.rs:224–260  ·  view source on GitHub ↗
(
    binary: BinaryExpr,
    guarantees: &HashMap<&Expr, &NullableInterval>,
)

Source from the content-addressed store, hash-verified

222}
223
224fn rewrite_binary_expr(
225 binary: BinaryExpr,
226 guarantees: &HashMap<&Expr, &NullableInterval>,
227) -> Result<Transformed<Expr>, DataFusionError> {
228 // The left or right side of expression might either have a guarantee
229 // or be a literal. Either way, we can resolve them to a NullableInterval.
230 let left_interval = guarantees
231 .get(binary.left.as_ref())
232 .map(|interval| Cow::Borrowed(*interval))
233 .or_else(|| {
234 if let Expr::Literal(value, _) = binary.left.as_ref() {
235 Some(Cow::Owned(value.clone().into()))
236 } else {
237 None
238 }
239 });
240 let right_interval = guarantees
241 .get(binary.right.as_ref())
242 .map(|interval| Cow::Borrowed(*interval))
243 .or_else(|| {
244 if let Expr::Literal(value, _) = binary.right.as_ref() {
245 Some(Cow::Owned(value.clone().into()))
246 } else {
247 None
248 }
249 });
250
251 if let (Some(left_interval), Some(right_interval)) = (left_interval, right_interval) {
252 let result = left_interval.apply_operator(&binary.op, right_interval.as_ref())?;
253 if result.is_certainly_true() {
254 return Ok(Transformed::yes(lit(true)));
255 } else if result.is_certainly_false() {
256 return Ok(Transformed::yes(lit(false)));
257 }
258 }
259 Ok(Transformed::no(Expr::BinaryExpr(binary)))
260}
261
262fn rewrite_inlist(
263 inlist: InList,

Callers 1

rewrite_exprFunction · 0.85

Calls 10

apply_operatorMethod · 0.80
is_certainly_trueMethod · 0.80
is_certainly_falseMethod · 0.80
litFunction · 0.50
BinaryExprClass · 0.50
mapMethod · 0.45
getMethod · 0.45
as_refMethod · 0.45
intoMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…