petern48 commented on code in PR #241:
URL: https://github.com/apache/sedona-db/pull/241#discussion_r2463155943


##########
c/sedona-geos/src/register.rs:
##########
@@ -37,6 +44,7 @@ pub fn scalar_kernels() -> Vec<(&'static str, 
ScalarKernelRef)> {
     vec![
         ("st_area", st_area_impl()),
         ("st_buffer", st_buffer_impl()),
+        ("st_buffer_style", st_buffer_style_impl()),

Review Comment:
   ```suggestion
           ("st_buffer", st_buffer_style_impl()),
   ```
   
   This string here represents the actual string we call in SQL, so we actually 
want this to be `"st_buffer"` and not `"st_buffer_style"`. With this current 
code, we have to instead call it like below.
   ```
   select st_buffer_style(st_geomfromtext('point (0 0)'), 1, '');
   ```



##########
c/sedona-geos/src/st_buffer.rs:
##########
@@ -115,6 +124,136 @@ fn invoke_scalar(
     Ok(())
 }
 
+fn extract_optional_f64(arg: &ColumnarValue) -> Result<Option<f64>> {
+    let casted = arg.cast_to(&DataType::Float64, None)?;
+    match &casted {
+        ColumnarValue::Scalar(scalar) if !scalar.is_null() => {
+            Ok(Some(f64::try_from(scalar.clone())?))
+        }
+        ColumnarValue::Scalar(_) => Ok(None),
+        _ => Err(DataFusionError::Execution(format!(
+            "Expected scalar distance, got: {:?}",
+            arg
+        ))),
+    }
+}
+
+fn extract_optional_bool(arg: Option<&ColumnarValue>) -> Result<Option<bool>> {
+    let Some(arg) = arg else { return Ok(None) };
+    let casted = arg.cast_to(&DataType::Boolean, None)?;
+    match &casted {
+        ColumnarValue::Scalar(scalar) if !scalar.is_null() => {
+            Ok(Some(bool::try_from(scalar.clone())?))
+        }
+        ColumnarValue::Scalar(_) => Ok(None),
+        _ => Err(DataFusionError::Execution(format!(
+            "Expected scalar useSpheroid parameter, got: {:?}",
+            arg
+        ))),
+    }
+}
+
+fn extract_optional_string(arg: Option<&ColumnarValue>) -> 
Result<Option<String>> {
+    let Some(arg) = arg else { return Ok(None) };
+    let casted = arg.cast_to(&DataType::Utf8, None)?;
+    match &casted {
+        ColumnarValue::Scalar(ScalarValue::Utf8(Some(s)) | 
ScalarValue::LargeUtf8(Some(s))) => {
+            Ok(Some(s.clone()))
+        }
+        ColumnarValue::Scalar(scalar) if scalar.is_null() => Ok(None),
+        ColumnarValue::Scalar(_) => Ok(None),
+        _ => Err(DataFusionError::Execution(format!(
+            "Expected scalar bufferStyleParameters, got: {:?}",
+            arg
+        ))),
+    }
+}
+
+fn parse_buffer_params(params_str: Option<&str>) -> Result<BufferParams> {

Review Comment:
   Yes, let's definitely add negative tests. Some ideas: invalid keys (e.g 
`key1=2`), invalid value types (e.g `mitre_limit=abcd`).
   
   Add a test for empty string (which should work). We should have some at the 
Python level, as well in case we add new kernels from another library (though 
idk how likely that is, considering `geo` doesn't support all params).



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