Skip to content

Commit 29b8af2

Browse files
authored
Minor: Change LiteralGuarantee try_new to new (#12669)
* Change try_new to new, it is not fallible * Fix formatting
1 parent 251c354 commit 29b8af2

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

datafusion/physical-expr/src/utils/guarantee.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,18 @@ impl LiteralGuarantee {
9393
/// Create a new instance of the guarantee if the provided operator is
9494
/// supported. Returns None otherwise. See [`LiteralGuarantee::analyze`] to
9595
/// create these structures from an predicate (boolean expression).
96-
fn try_new<'a>(
96+
fn new<'a>(
9797
column_name: impl Into<String>,
9898
guarantee: Guarantee,
9999
literals: impl IntoIterator<Item = &'a ScalarValue>,
100-
) -> Option<Self> {
100+
) -> Self {
101101
let literals: HashSet<_> = literals.into_iter().cloned().collect();
102102

103-
Some(Self {
103+
Self {
104104
column: Column::from_name(column_name),
105105
guarantee,
106106
literals,
107-
})
107+
}
108108
}
109109

110110
/// Return a list of [`LiteralGuarantee`]s that must be satisfied for `expr`
@@ -338,13 +338,10 @@ impl<'a> GuaranteeBuilder<'a> {
338338
// This is a new guarantee
339339
let new_values: HashSet<_> = new_values.into_iter().collect();
340340

341-
if let Some(guarantee) =
342-
LiteralGuarantee::try_new(col.name(), guarantee, new_values)
343-
{
344-
// add it to the list of guarantees
345-
self.guarantees.push(Some(guarantee));
346-
self.map.insert(key, self.guarantees.len() - 1);
347-
}
341+
let guarantee = LiteralGuarantee::new(col.name(), guarantee, new_values);
342+
// add it to the list of guarantees
343+
self.guarantees.push(Some(guarantee));
344+
self.map.insert(key, self.guarantees.len() - 1);
348345
}
349346

350347
self
@@ -851,7 +848,7 @@ mod test {
851848
S: Into<ScalarValue> + 'a,
852849
{
853850
let literals: Vec<_> = literals.into_iter().map(|s| s.into()).collect();
854-
LiteralGuarantee::try_new(column, Guarantee::In, literals.iter()).unwrap()
851+
LiteralGuarantee::new(column, Guarantee::In, literals.iter())
855852
}
856853

857854
/// Guarantee that the expression is true if the column is NOT any of the specified values
@@ -861,7 +858,7 @@ mod test {
861858
S: Into<ScalarValue> + 'a,
862859
{
863860
let literals: Vec<_> = literals.into_iter().map(|s| s.into()).collect();
864-
LiteralGuarantee::try_new(column, Guarantee::NotIn, literals.iter()).unwrap()
861+
LiteralGuarantee::new(column, Guarantee::NotIn, literals.iter())
865862
}
866863

867864
// Schema for testing

0 commit comments

Comments
 (0)