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
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>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @pgwhalen -- this is a nice change and cleanup and makes sense to me

In order to make this change easier on downstream crates, can you please add back a version of try_new() that is marked "deprecated" with instructions on how to change the code that just calls new()

Here is an example

#[deprecated(note = "please use `try_new` instead")]
pub fn new(config: RuntimeConfig) -> Result<Self> {
Self::try_new(config)
}

Having a deprecation marking means that users will get a message from the compiler telling them what to do rather than having to track it down themselves

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotcha, I will add tonight! I'd assumed it wasn't an issue because the function is not pub (it seems the main public interface to create LiteralGuarantees is analyze) - but I'm a little new to rust so I have some gaps in knowledge of how visibility works.

Copy link
Contributor

Choose a reason for hiding this comment

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

but I'm a little new to rust so I have some gaps in knowledge of how visibility works.

When in doubt I go to the docs.rs page:
https://docs.rs/datafusion/latest/datafusion/physical_expr/utils/struct.LiteralGuarantee.html

An in this case, I think you are right that this is a non pub method and therefore there is no downstream API implications.

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