jamxia155 commented on code in PR #14194:
URL: https://github.com/apache/datafusion/pull/14194#discussion_r1956624318


##########
datafusion/substrait/src/logical_plan/producer.rs:
##########
@@ -559,12 +562,62 @@ pub fn from_table_scan(
     let table_schema = scan.source.schema().to_dfschema_ref()?;
     let base_schema = to_substrait_named_struct(&table_schema)?;
 
+    let mut filter_option = None;
+    let mut best_effort_filter_option = None;
+
+    if !scan.filters.is_empty() {
+        let mut full_filters = vec![];
+        let mut partial_filters = vec![];
+        let mut unsupported_filters = vec![];
+        let filter_refs: Vec<&Expr> = scan.filters.iter().collect();
+
+        if let Ok(results) = 
scan.source.supports_filters_pushdown(&filter_refs) {
+            scan.filters
+                .iter()
+                .zip(results.iter())
+                .for_each(|(x, res)| match res {
+                    TableProviderFilterPushDown::Exact => 
full_filters.push(x.clone()),
+                    TableProviderFilterPushDown::Inexact => {
+                        partial_filters.push(x.clone())
+                    }
+                    TableProviderFilterPushDown::Unsupported => {
+                        unsupported_filters.push(x.clone())
+                    }
+                });
+        }
+
+        let table_schema_qualified =
+            Arc::new(if !full_filters.is_empty() || 
!partial_filters.is_empty() {
+                DFSchema::try_from_qualified_schema(
+                    scan.table_name.clone(),
+                    &(scan.source.schema()),
+                )
+                .unwrap()
+            } else {
+                DFSchema::empty()
+            });
+
+        if !full_filters.is_empty() {
+            let combined_expr = conjunction(full_filters).unwrap();
+            let filter_expr =
+                producer.handle_expr(&combined_expr, &table_schema_qualified)?;
+            filter_option = Some(Box::new(filter_expr));
+        }

Review Comment:
   Appreciate the sentiment but there's a gotcha here: we only wish to do the 
work of handling the filter expressions if `scan.filters` is not empty, but the 
variables `filter_option` and `best_effort_filter_option` are needed to 
construct the `ReadRel` at the end even if their values remain as `None` so 
they need to be declared outside the scope of the conditional.



-- 
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: github-unsubscr...@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org
For additional commands, e-mail: github-h...@datafusion.apache.org

Reply via email to