Kontinuation commented on code in PR #33: URL: https://github.com/apache/sedona-db/pull/33#discussion_r2329095040
########## rust/sedona-geo/src/st_centroid.rs: ########## @@ -0,0 +1,144 @@ +// 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::sync::Arc; + +use arrow_array::builder::BinaryBuilder; +use datafusion_common::error::Result; +use datafusion_expr::ColumnarValue; +use geo_generic_alg::Centroid; +use sedona_expr::scalar_udf::{ArgMatcher, ScalarKernelRef, SedonaScalarKernel}; +use sedona_functions::executor::WkbExecutor; +use sedona_functions::st_isempty::is_wkb_empty; +use sedona_schema::datatypes::{SedonaType, WKB_GEOMETRY}; +use wkb::reader::Wkb; + +use sedona_geometry::wkb_factory; +use sedona_testing::fixtures::POINT_EMPTY_WKB; + +/// ST_Centroid() implementation using centroid extraction +pub fn st_centroid_impl() -> ScalarKernelRef { + Arc::new(STCentroid {}) +} + +#[derive(Debug)] +struct STCentroid {} + +impl SedonaScalarKernel for STCentroid { + fn return_type(&self, args: &[SedonaType]) -> Result<Option<SedonaType>> { + let matcher = ArgMatcher::new(vec![ArgMatcher::is_geometry()], WKB_GEOMETRY); + + matcher.match_args(args) + } + + fn invoke_batch( + &self, + arg_types: &[SedonaType], + args: &[ColumnarValue], + ) -> Result<ColumnarValue> { + let executor = WkbExecutor::new(arg_types, args); + let mut builder = BinaryBuilder::with_capacity(executor.num_iterations(), 1024); + executor.execute_wkb_void(|maybe_wkb| { + match maybe_wkb { + Some(wkb) => { + let centroid_wkb = invoke_scalar(&wkb)?; + builder.append_value(¢roid_wkb); + } + _ => builder.append_null(), + } + + Ok(()) + })?; + + executor.finish(Arc::new(builder.finish())) + } +} + +fn invoke_scalar(wkb: &Wkb) -> Result<Vec<u8>> { + // Check for empty geometries first - they should return POINT EMPTY + if is_wkb_empty(wkb)? { + return Ok(POINT_EMPTY_WKB.to_vec()); Review Comment: nit: I'm not sure if using constants defined in `sedona_testing::fixtures` is a good idea. We can move the constant definition to somewhere else if the production code needs it. ########## .github/workflows/rust.yml: ########## @@ -99,6 +104,24 @@ jobs: # Update this key to force a new cache prefix-key: "rust-${{ matrix.name }}-v1" + - name: Free up disk space + run: | + echo "Available disk space before cleanup:" + df -h / + + # Remove unnecessary packages and files + sudo apt-get clean + sudo rm -rf /usr/share/dotnet + sudo rm -rf /usr/local/lib/android + sudo rm -rf /opt/ghc + sudo rm -rf /opt/hostedtoolcache/CodeQL + sudo rm -rf /usr/local/share/boost + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + docker system prune -af + + echo "Available disk space after cleanup:" + df -h / Review Comment: Can we use [`jlumbroso/free-disk-space`](https://github.com/jlumbroso/free-disk-space) for freeing up disk space? Apache Iceberg is also using it https://github.com/apache/iceberg/blob/c8541db1c905e05891596ffe157c12392e38c93c/.github/workflows/spark-ci.yml#L100-L102 -- 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]
