You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "ozankabak (via GitHub)" <gi...@apache.org> on 2023/09/12 06:24:33 UTC

[GitHub] [arrow-datafusion] ozankabak commented on a diff in pull request #7467: feat: add guarantees to simplification

ozankabak commented on code in PR #7467:
URL: https://github.com/apache/arrow-datafusion/pull/7467#discussion_r1322482566


##########
datafusion/physical-expr/src/intervals/interval_aritmetic.rs:
##########
@@ -686,6 +715,231 @@ fn calculate_cardinality_based_on_bounds(
     }
 }
 
+/// The null status of an [NullableInterval].
+///
+/// This is an internal convenience that can be used in match statements
+/// (unlike Interval).
+#[derive(Debug, Clone, PartialEq, Eq)]
+enum NullStatus {
+    /// The interval is guaranteed to be non-null.
+    Never,
+    /// The interval is guaranteed to be null.
+    Always,
+    /// The interval isn't guaranteed to never be null or always be null.
+    Maybe,
+}
+
+/// An [Interval] that also tracks null status using a boolean interval.
+///
+/// This represents values that may be in a particular range or be null.
+///
+/// # Examples
+///
+/// ```
+/// use datafusion_physical_expr::intervals::{Interval, NullableInterval};
+/// use datafusion_common::ScalarValue;
+///
+/// // [1, 2) U {NULL}
+/// NullableInterval {
+///    values: Interval::make(Some(1), Some(2), (false, true)),
+///    is_valid: Interval::UNCERTAIN,
+/// };
+///
+/// // (0, ∞)
+/// NullableInterval {
+///   values: Interval::make(Some(0), None, (true, true)),
+///   is_valid: Interval::CERTAINLY_TRUE,
+/// };
+///
+/// // {NULL}
+/// NullableInterval::from(&ScalarValue::Int32(None));
+///
+/// // {4}
+/// NullableInterval::from(&ScalarValue::Int32(Some(4)));
+/// ```
+#[derive(Debug, Clone, PartialEq, Eq, Default)]
+pub struct NullableInterval {
+    /// The interval for the values
+    pub values: Interval,
+    /// A boolean interval representing whether the value is certainly valid
+    /// (not null), certainly null, or has an unknown validity. This takes
+    /// precedence over the values in the interval: if this field is equal to
+    /// [Interval::CERTAINLY_FALSE], then the interval is certainly null
+    /// regardless of what `values` is.
+    pub is_valid: Interval,

Review Comment:
   Looks good to me!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org