cisaacson commented on code in PR #9988:
URL: https://github.com/apache/arrow-datafusion/pull/9988#discussion_r1556329614
##########
datafusion/core/src/datasource/provider.rs:
##########
@@ -161,20 +161,54 @@ pub trait TableProvider: Sync + Send {
/// Specify if DataFusion should provide filter expressions to the
/// TableProvider to apply *during* the scan.
///
- /// The return value must have one element for each filter expression
passed
- /// in. The value of each element indicates if the TableProvider can apply
- /// that particular filter during the scan.
- ///
/// Some TableProviders can evaluate filters more efficiently than the
/// `Filter` operator in DataFusion, for example by using an index.
- ///
- /// By default, returns [`Unsupported`] for all filters, meaning no filters
+ ///
+ /// The return value must have one element for each filter expression
passed
+ /// in. The value of each element indicates if the TableProvider can apply
+ /// that particular filter during the scan. The position in the return
value
+ /// Vec corresponds to the expression in the `filters` input.
+ ///
+ /// Here is an example of how this can be done:
+ ///
+ /// ```
+ /// fn supports_filters_pushdown(
+ /// &self,
+ /// filters: &[&Expr],) -> Result<Vec<TableProviderFilterPushDown>> {
+ ///
+ /// let result_vec: Vec<TableProviderFilterPushDown> =
Vec::with_capacity(&filters.len());
+ /// for i in 0..filters.len() {
+ /// // Evaluate a filter
+ /// let filter = filters[i];
+ ///
+ /// // Evaluate a filter to support here
+ /// if filter ... {
+ /// result_vec.push(TableProviderFilterPushDown::Exact);
+ /// } else {
+ /// result_vec.push(TableProviderFilterPushDown::Unsupported);
+ /// }
+ /// }
Review Comment:
Let me know if the latest commit looks OK to you. I didn't see the
functional style example until just now, but my example does compile. I bet you
may have a better way to do the whole thing, I'm interested in that feedback
too. I can look at this again this evening. And I could easily convert it to
functional style too. If I put another fn in to evaluate each filter (which is
how I would do it) then that would have to be in the example too? That will
make it a lot longer so I put just one Expr eval to show the concept.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]