Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion datafusion/physical-expr/src/intervals/interval_aritmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,14 @@ impl Default for Interval {

impl Display for Interval {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "Interval [{}, {}]", self.lower, self.upper)
write!(
f,
"{}{}, {}{}",
if self.lower.open { "(" } else { "[" },
self.lower.value,
self.upper.value,
if self.upper.open { ")" } else { "]" }
)
}
}

Expand Down Expand Up @@ -1785,4 +1792,31 @@ mod tests {

Ok(())
}

#[test]
fn test_interval_display() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both test cases result in (...], i.e. they don't really cover the if-else clauses within the formatter. I think having the 4 permutations ((...), [...), [...], (...]) would be nice.

let interval = Interval::new(
IntervalBound::new(ScalarValue::from(0.25_f32), true),
IntervalBound::new(ScalarValue::from(0.50_f32), false),
);
assert_eq!(format!("{}", interval), "(0.25, 0.5]");

let interval = Interval::new(
IntervalBound::new(ScalarValue::from(0.25_f32), false),
IntervalBound::new(ScalarValue::from(0.50_f32), true),
);
assert_eq!(format!("{}", interval), "[0.25, 0.5)");

let interval = Interval::new(
IntervalBound::new(ScalarValue::from(0.25_f32), true),
IntervalBound::new(ScalarValue::from(0.50_f32), true),
);
assert_eq!(format!("{}", interval), "(0.25, 0.5)");

let interval = Interval::new(
IntervalBound::new(ScalarValue::from(0.25_f32), false),
IntervalBound::new(ScalarValue::from(0.50_f32), false),
);
assert_eq!(format!("{}", interval), "[0.25, 0.5]");
}
}