james-willis commented on code in PR #1163:
URL: https://github.com/apache/sedona-db/pull/1163#discussion_r3866425485


##########
rust/sedona-functions/src/st_geohash.rs:
##########
@@ -0,0 +1,1459 @@
+// 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::{collections::HashMap, iter::zip, sync::Arc};
+
+use crate::executor::WkbExecutor;
+use arrow_array::{builder::StringBuilder, Array};
+use arrow_schema::DataType;
+use datafusion_common::{
+    cast::{as_int64_array, as_string_view_array, as_struct_array},
+    config::ConfigOptions,
+    error::{DataFusionError, Result},
+    exec_err, plan_err, ScalarValue,
+};
+use datafusion_expr::{ColumnarValue, Volatility};
+use geo_traits::{GeometryTrait, GeometryType};
+use sedona_common::{option::SedonaOptions, sedona_internal_datafusion_err, 
sedona_internal_err};
+use sedona_expr::{
+    item_crs::parse_item_crs_arg_type,
+    scalar_udf::{SedonaScalarKernel, SedonaScalarUDF},
+};
+use sedona_geometry::{
+    bounds::{WkbBounder2D, WkbBounder2DFactory},
+    interval::{Interval, IntervalTrait, WraparoundInterval},
+    types::Edges,
+};
+use sedona_schema::{
+    crs::{deserialize_crs, lnglat},
+    datatypes::SedonaType,
+    matchers::ArgMatcher,
+};
+use wkb::reader::Wkb;
+
+/// The base32 alphabet used by geohash encoding (Gustavo Niemeyer's 
specification)
+const BASE32: &[u8; 32] = b"0123456789bcdefghjkmnpqrstuvwxyz";
+
+/// The maximum number of geohash characters (matches Apache Sedona's
+/// PointGeoHashEncoder, which caps precision at 20)
+const MAX_PRECISION: i64 = 20;
+
+/// ST_GeoHash() scalar UDF
+///
+/// Native implementation to compute the geohash of a geometry or geography.
+/// The two-argument form hashes at the requested precision (number of base32
+/// characters); the one-argument form hashes a point at [MAX_PRECISION].
+pub fn st_geohash_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "st_geohash",
+        // ST_GeoHash cannot use ItemCrsKernel::wrap_impl(): that wrapper 
strips
+        // the CRS before calling the inner kernel, which is what makes it free
+        // for functions like ST_Area() whose answer does not depend on the 
CRS.
+        // This one rejects a non-WGS84 CRS, so it needs to see it. The sibling
+        // kernels below are the same shape ST_SRID() and ST_CRS() use, one
+        // matching the plain types and one matching item_crs.
+        vec![
+            Arc::new(STGeoHashItemCrs {
+                matcher: ArgMatcher::new(
+                    vec![ArgMatcher::is_item_crs()],

Review Comment:
   This is a structural issue of how `is_item_crs` is used in UDFs - ST_SRID, 
ST_CRS, and ST_EWKB use the same pattern.
   
   I will raise a stacked PR on top of this one to fix. Will link when ready



##########
rust/sedona-functions/src/st_geohash.rs:
##########
@@ -0,0 +1,1459 @@
+// 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::{collections::HashMap, iter::zip, sync::Arc};
+
+use crate::executor::WkbExecutor;
+use arrow_array::{builder::StringBuilder, Array};
+use arrow_schema::DataType;
+use datafusion_common::{
+    cast::{as_int64_array, as_string_view_array, as_struct_array},
+    config::ConfigOptions,
+    error::{DataFusionError, Result},
+    exec_err, plan_err, ScalarValue,
+};
+use datafusion_expr::{ColumnarValue, Volatility};
+use geo_traits::{GeometryTrait, GeometryType};
+use sedona_common::{option::SedonaOptions, sedona_internal_datafusion_err, 
sedona_internal_err};
+use sedona_expr::{
+    item_crs::parse_item_crs_arg_type,
+    scalar_udf::{SedonaScalarKernel, SedonaScalarUDF},
+};
+use sedona_geometry::{
+    bounds::{WkbBounder2D, WkbBounder2DFactory},
+    interval::{Interval, IntervalTrait, WraparoundInterval},
+    types::Edges,
+};
+use sedona_schema::{
+    crs::{deserialize_crs, lnglat},
+    datatypes::SedonaType,
+    matchers::ArgMatcher,
+};
+use wkb::reader::Wkb;
+
+/// The base32 alphabet used by geohash encoding (Gustavo Niemeyer's 
specification)
+const BASE32: &[u8; 32] = b"0123456789bcdefghjkmnpqrstuvwxyz";
+
+/// The maximum number of geohash characters (matches Apache Sedona's
+/// PointGeoHashEncoder, which caps precision at 20)
+const MAX_PRECISION: i64 = 20;
+
+/// ST_GeoHash() scalar UDF
+///
+/// Native implementation to compute the geohash of a geometry or geography.
+/// The two-argument form hashes at the requested precision (number of base32
+/// characters); the one-argument form hashes a point at [MAX_PRECISION].
+pub fn st_geohash_udf() -> SedonaScalarUDF {
+    SedonaScalarUDF::new(
+        "st_geohash",
+        // ST_GeoHash cannot use ItemCrsKernel::wrap_impl(): that wrapper 
strips
+        // the CRS before calling the inner kernel, which is what makes it free
+        // for functions like ST_Area() whose answer does not depend on the 
CRS.
+        // This one rejects a non-WGS84 CRS, so it needs to see it. The sibling
+        // kernels below are the same shape ST_SRID() and ST_CRS() use, one
+        // matching the plain types and one matching item_crs.
+        vec![
+            Arc::new(STGeoHashItemCrs {
+                matcher: ArgMatcher::new(
+                    vec![ArgMatcher::is_item_crs()],

Review Comment:
   This is a structural issue of how `is_item_crs` is used in UDFs - ST_SRID, 
ST_CRS, and ST_EWKB use the same pattern.
   
   I will raise a stacked PR on top of this one to fix. Will link when drafted



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