Skip to content

Commit

Permalink
Minor: Change LiteralGuarantee try_new to new (apache#12669)
Browse files Browse the repository at this point in the history
* Change try_new to new, it is not fallible

* Fix formatting
  • Loading branch information
pgwhalen authored Sep 30, 2024
1 parent 251c354 commit 29b8af2
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions datafusion/physical-expr/src/utils/guarantee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ impl LiteralGuarantee {
/// Create a new instance of the guarantee if the provided operator is
/// supported. Returns None otherwise. See [`LiteralGuarantee::analyze`] to
/// create these structures from an predicate (boolean expression).
fn try_new<'a>(
fn new<'a>(
column_name: impl Into<String>,
guarantee: Guarantee,
literals: impl IntoIterator<Item = &'a ScalarValue>,
) -> Option<Self> {
) -> Self {
let literals: HashSet<_> = literals.into_iter().cloned().collect();

Some(Self {
Self {
column: Column::from_name(column_name),
guarantee,
literals,
})
}
}

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

if let Some(guarantee) =
LiteralGuarantee::try_new(col.name(), guarantee, new_values)
{
// add it to the list of guarantees
self.guarantees.push(Some(guarantee));
self.map.insert(key, self.guarantees.len() - 1);
}
let guarantee = LiteralGuarantee::new(col.name(), guarantee, new_values);
// add it to the list of guarantees
self.guarantees.push(Some(guarantee));
self.map.insert(key, self.guarantees.len() - 1);
}

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

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

// Schema for testing
Expand Down

0 comments on commit 29b8af2

Please sign in to comment.