alamb commented on code in PR #9988:
URL: https://github.com/apache/arrow-datafusion/pull/9988#discussion_r1556212768


##########
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:
+    /// 
+    /// ```

Review Comment:
   In rust any example like this is actually compiled and run (more details are 
here 
https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html)
   
   So to get this example to work you'll need to add some `use` etc commands



##########
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:
   If you like a more functional style, I think you can write this same logic 
in this way:
   
   ```suggestion
       ///     let result_vec: Vec<TableProviderFilterPushDown> = filters.iter()
       ///     .map (|filter| 
       ///         // Evaluate a filter
       /// 
       ///         // Evaluate a filter to support here
       ///         if can_support_filter(filter){
       ///             TableProviderFilterPushDown::Exact
       ///         } else {
       ///             TableProviderFilterPushDown::Unsupported;
       ///         }
       ///     }).collect();
   ```



-- 
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]

Reply via email to