paleolimbot commented on code in PR #1207:
URL: https://github.com/apache/sedona-db/pull/1207#discussion_r3937873773


##########
rust/sedona-expr/src/spatial_filter.rs:
##########
@@ -488,6 +499,83 @@ impl SpatialFilterFactory {
     }
 }
 
+/// Convert the small logical-expression subset understood by the spatial 
filter
+/// parser to its physical counterparts. This keeps logical and physical 
parsing
+/// on the same implementation path.
+fn logical_to_physical_expr(expr: &Expr) -> Result<Arc<dyn PhysicalExpr>> {
+    match expr {
+        Expr::Column(column) => Ok(Arc::new(Column::new(&column.name, 0))),
+        Expr::Literal(value, metadata) => 
Ok(Arc::new(Literal::new_with_metadata(
+            value.clone(),
+            metadata.clone(),
+        ))),
+        Expr::BinaryExpr(binary) => Ok(Arc::new(BinaryExpr::new(
+            logical_to_physical_expr(&binary.left)?,
+            binary.op,
+            logical_to_physical_expr(&binary.right)?,
+        ))),
+        Expr::ScalarFunction(function) => {
+            let args = function
+                .args
+                .iter()
+                .map(logical_to_physical_expr)
+                .collect::<Result<Vec<_>>>()?;
+            let return_type = if function.func.name() == "st_distance" {
+                DataType::Float64
+            } else {
+                DataType::Boolean
+            };
+            Ok(Arc::new(ScalarFunctionExpr::new(
+                function.func.name(),
+                Arc::clone(&function.func),
+                args,
+                Arc::new(Field::new("", return_type, true)),
+                Arc::new(ConfigOptions::default()),
+            )))
+        }
+        // Preserve an unsupported node as a physical expression that the 
shared
+        // argument parser will classify as `Other`.
+        _ => Ok(Arc::new(UnknownSentinelExpr)),

Review Comment:
   This will translate into `SpatialFilter::Unknown` (which will prevent 
pruning, since Unknown could evaluate to True).



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