Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: beautify interval display #7554

Merged
merged 2 commits into from
Sep 14, 2023
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]");
}
}