Copilot commented on code in PR #360:
URL: https://github.com/apache/sedona-db/pull/360#discussion_r2561123703


##########
rust/sedona-schema/src/crs.rs:
##########
@@ -97,10 +97,37 @@ impl PartialEq<dyn CoordinateReferenceSystem + Send + Sync>
 /// A trait defining the minimum required properties of a concrete coordinate
 /// reference system, allowing the details of this to be implemented elsewhere.
 pub trait CoordinateReferenceSystem: Debug {
+    /// Compute the representation of this Crs in the form required for JSON 
output
+    ///
+    /// The output must be valid JSON (e.g., arbitrary strings must be quoted).
     fn to_json(&self) -> String;
+
+    /// Compute the representation of this Crs as a string in the form 
Authority:Code
+    ///
+    /// If there is no such representation, returns None.
     fn to_authority_code(&self) -> Result<Option<String>>;
+
+    /// Compute CRS equality
+    ///
+    /// CRS equality is a relatively thorny topic and can be difficult to 
compute;
+    /// however, this method should try to compare self and other on value 
(e.g.,
+    /// comparing authority_code where possible).
     fn crs_equals(&self, other: &dyn CoordinateReferenceSystem) -> bool;
+
+    /// Reduce this beautiful, rich CRS representation to a mere integer if 
possible

Review Comment:
   [nitpick] The comment contains subjective language ('beautiful, rich', 
'mere'). Consider using more neutral, technical language such as 'Convert this 
CRS representation to an integer SRID if possible'.
   ```suggestion
       /// Convert this CRS representation to an integer SRID if possible.
   ```



##########
c/sedona-proj/src/sd_order_lnglat.rs:
##########
@@ -0,0 +1,205 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::{fmt::Debug, sync::Arc};
+
+use arrow_array::builder::UInt64Builder;
+use arrow_schema::DataType;
+use datafusion_common::{DataFusionError, Result};
+use datafusion_expr::ColumnarValue;
+use sedona_expr::scalar_udf::SedonaScalarKernel;
+use sedona_functions::executor::WkbBytesExecutor;
+use sedona_geometry::{transform::CrsEngine, wkb_header::WkbHeader};
+use sedona_schema::{crs::lnglat, datatypes::SedonaType, matchers::ArgMatcher};
+
+use crate::st_transform::with_global_proj_engine;
+
+/// Generic scalar kernel for sd_order based on the first coordinate
+/// of a geometry projected to lon/lat
+///
+/// This [SedonaScalarKernel] requires the actual function (e.g., S2, H3,
+/// or A5 cell identifier) to be provided but takes care of the extraction
+/// of the first coordinate and projecting to lon/lat space. The provided
+/// function must return a `u64`.
+pub struct OrderLngLat<F> {
+    order_fn: F,
+}
+
+impl<F: Fn((f64, f64)) -> u64> OrderLngLat<F> {
+    /// Create a new kernel from the required function type
+    pub fn new(order_fn: F) -> Self {
+        Self { order_fn }
+    }
+}
+
+impl<F: Fn((f64, f64)) -> u64> Debug for OrderLngLat<F> {
+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+        f.debug_struct("OrderLngLat").finish()
+    }
+}
+
+impl<F: Fn((f64, f64)) -> u64> SedonaScalarKernel for OrderLngLat<F> {
+    fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> {
+        let matcher = ArgMatcher::new(
+            vec![ArgMatcher::is_geometry_or_geography()],
+            SedonaType::Arrow(DataType::UInt64),
+        );
+        matcher.match_args(args)
+    }
+
+    fn invoke_batch(
+        &self,
+        arg_types: &[SedonaType],
+        args: &[ColumnarValue],
+    ) -> Result<ColumnarValue> {
+        // Extract the source CRS, checking for lon/lat to see if we can avoid
+        // a transformation. If the CRS is missing we also skip any particular
+        // transform (although the resulting sort may not be effective).
+        let maybe_src_crs = match &arg_types[0] {
+            SedonaType::Wkb(_, maybe_crs) | SedonaType::WkbView(_, maybe_crs)
+                if maybe_crs != &lnglat() =>

Review Comment:
   The condition `maybe_crs != &lnglat()` calls `lnglat()` on every iteration. 
Consider storing the result of `lnglat()` in a variable before the loop to 
avoid repeated allocations.
   ```suggestion
           let lnglat_crs = lnglat();
           let maybe_src_crs = match &arg_types[0] {
               SedonaType::Wkb(_, maybe_crs) | SedonaType::WkbView(_, maybe_crs)
                   if maybe_crs != &lnglat_crs =>
   ```



##########
rust/sedona-schema/src/crs.rs:
##########
@@ -97,10 +97,37 @@ impl PartialEq<dyn CoordinateReferenceSystem + Send + Sync>
 /// A trait defining the minimum required properties of a concrete coordinate
 /// reference system, allowing the details of this to be implemented elsewhere.
 pub trait CoordinateReferenceSystem: Debug {
+    /// Compute the representation of this Crs in the form required for JSON 
output
+    ///
+    /// The output must be valid JSON (e.g., arbitrary strings must be quoted).
     fn to_json(&self) -> String;
+
+    /// Compute the representation of this Crs as a string in the form 
Authority:Code
+    ///
+    /// If there is no such representation, returns None.
     fn to_authority_code(&self) -> Result<Option<String>>;
+
+    /// Compute CRS equality
+    ///
+    /// CRS equality is a relatively thorny topic and can be difficult to 
compute;
+    /// however, this method should try to compare self and other on value 
(e.g.,
+    /// comparing authority_code where possible).
     fn crs_equals(&self, other: &dyn CoordinateReferenceSystem) -> bool;
+
+    /// Reduce this beautiful, rich CRS representation to a mere integer if 
possible
+    ///
+    /// For the purposes of this trait, an SRID is always equivalent to the
+    /// authority_code `"EPSG<srid>"`. Note that other SRID representations

Review Comment:
   Corrected formatting: should be `\"EPSG:{srid}\"` to match the actual format 
shown in line 267.
   ```suggestion
       /// authority_code `"EPSG:{srid}"`. Note that other SRID representations
   ```



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