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

Function satisfy_greater

datafusion/expr-common/src/interval_arithmetic.rs:1391–1450  ·  view source on GitHub ↗

This function updates the given intervals by enforcing (i.e. propagating) the inequality `left > right` (or the `left >= right` inequality, if `strict` is `true`). Returns a `Result` wrapping an `Option` containing the tuple of resulting intervals. If the comparison is infeasible, returns `None`. Example usage: ``` use datafusion_common::DataFusionError; use datafusion_expr_common::interval_arit

(
    left: &Interval,
    right: &Interval,
    strict: bool,
)

Source from the content-addressed store, hash-verified

1389/// Attempting to compare intervals of different data types will lead
1390/// to an error.
1391pub fn satisfy_greater(
1392 left: &Interval,
1393 right: &Interval,
1394 strict: bool,
1395) -> Result<Option<(Interval, Interval)>> {
1396 let lhs_type = left.data_type();
1397 let rhs_type = right.data_type();
1398 assert_eq_or_internal_err!(
1399 lhs_type.clone(),
1400 rhs_type.clone(),
1401 "Intervals must have the same data type, lhs:{}, rhs:{}",
1402 lhs_type,
1403 rhs_type
1404 );
1405
1406 if !left.upper.is_null() && left.upper <= right.lower {
1407 if !strict && left.upper == right.lower {
1408 // Singleton intervals:
1409 return Ok(Some((
1410 Interval::new(left.upper.clone(), left.upper.clone()),
1411 Interval::new(left.upper.clone(), left.upper.clone()),
1412 )));
1413 } else {
1414 // Left-hand side: <--======----0------------>
1415 // Right-hand side: <------------0--======---->
1416 // No intersection, infeasible to propagate:
1417 return Ok(None);
1418 }
1419 }
1420
1421 // Only the lower bound of left-hand side and the upper bound of the right-hand
1422 // side can change after propagating the greater-than operation.
1423 let new_left_lower = if left.lower.is_null() || left.lower <= right.lower {
1424 if strict {
1425 next_value(right.lower.clone())
1426 } else {
1427 right.lower.clone()
1428 }
1429 } else {
1430 left.lower.clone()
1431 };
1432 // Below code is asymmetric relative to the above if statement, because
1433 // `None` compares less than `Some` in Rust.
1434 let new_right_upper = if right.upper.is_null()
1435 || (!left.upper.is_null() && left.upper <= right.upper)
1436 {
1437 if strict {
1438 prev_value(left.upper.clone())
1439 } else {
1440 left.upper.clone()
1441 }
1442 } else {
1443 right.upper.clone()
1444 };
1445 // No possibility to create an invalid interval:
1446 Ok(Some((
1447 Interval::new(new_left_lower, left.upper.clone()),
1448 Interval::new(right.lower.clone(), new_right_upper),

Callers 1

propagate_comparisonFunction · 0.85

Calls 6

newFunction · 0.85
next_valueFunction · 0.85
prev_valueFunction · 0.85
data_typeMethod · 0.45
is_nullMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…