-
Notifications
You must be signed in to change notification settings - Fork 749
SEDONA-738 Add sedonadb worker #2593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
1c3aa88
15136e2
aeab0cb
f178f15
321fa81
503b334
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -631,6 +631,7 @@ | |
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-javadoc-plugin</artifactId> | ||
| <!-- <version>3.12.0</version>--> | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to remove |
||
| <version>2.10.4</version> | ||
| <executions> | ||
| <execution> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,12 +21,20 @@ | |
|
|
||
| import pandas as pd | ||
|
|
||
| from sedona.spark.sql.types import GeometryType | ||
| from sedona.spark.utils import geometry_serde | ||
| from pyspark.sql.udf import UserDefinedFunction | ||
| from pyspark.sql.types import DataType | ||
| from shapely.geometry.base import BaseGeometry | ||
| from pyspark.sql.udf import UserDefinedFunction | ||
| from sedona.spark.sql.types import GeometryType | ||
| from pyspark.sql.types import ( | ||
| DataType, | ||
| FloatType, | ||
| DoubleType, | ||
| IntegerType, | ||
| StringType, | ||
| ByteType, | ||
| ) | ||
|
|
||
| from sedona.spark.utils.geometry_serde import sedona_db_speedup_enabled | ||
|
|
||
| SEDONA_SCALAR_EVAL_TYPE = 5200 | ||
| SEDONA_PANDAS_ARROW_NAME = "SedonaPandasArrowUDF" | ||
|
|
@@ -142,3 +150,76 @@ def serialize_to_geometry_if_geom(data, return_type: DataType): | |
| return geometry_serde.serialize(data) | ||
|
|
||
| return data | ||
|
|
||
|
|
||
| def infer_pa_type(spark_type: DataType): | ||
| import pyarrow as pa | ||
| import geoarrow.pyarrow as ga | ||
|
|
||
| if isinstance(spark_type, GeometryType): | ||
| return ga.wkb() | ||
| elif isinstance(spark_type, FloatType): | ||
| return pa.float32() | ||
| elif isinstance(spark_type, DoubleType): | ||
| return pa.float64() | ||
| elif isinstance(spark_type, IntegerType): | ||
| return pa.int32() | ||
| elif isinstance(spark_type, StringType): | ||
| return pa.string() | ||
| else: | ||
| raise NotImplementedError(f"Type {spark_type} is not supported yet.") | ||
|
|
||
|
|
||
| def infer_input_type(spark_type: DataType): | ||
| from sedonadb import udf as sedona_udf_module | ||
|
|
||
| if isinstance(spark_type, GeometryType): | ||
| return sedona_udf_module.GEOMETRY | ||
| elif ( | ||
| isinstance(spark_type, FloatType) | ||
| or isinstance(spark_type, DoubleType) | ||
| or isinstance(spark_type, IntegerType) | ||
| ): | ||
| return sedona_udf_module.NUMERIC | ||
| elif isinstance(spark_type, StringType): | ||
| return sedona_udf_module.STRING | ||
| elif isinstance(spark_type, ByteType): | ||
| return sedona_udf_module.BINARY | ||
| else: | ||
| raise NotImplementedError(f"Type {spark_type} is not supported yet.") | ||
|
|
||
|
|
||
| def infer_input_types(spark_types: list[DataType]): | ||
| pa_types = [] | ||
| for spark_type in spark_types: | ||
| pa_type = infer_input_type(spark_type) | ||
| pa_types.append(pa_type) | ||
|
|
||
| return pa_types | ||
|
|
||
|
|
||
| def sedona_db_vectorized_udf( | ||
| return_type: DataType, | ||
| input_types: list[DataType], | ||
| ): | ||
| from sedonadb import udf as sedona_udf_module | ||
|
|
||
| eval_type = 6200 | ||
| if sedona_db_speedup_enabled: | ||
| eval_type = 6201 | ||
|
Comment on lines
+207
to
+209
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Define thse eval types as constants such as |
||
|
|
||
| def apply_fn(fn): | ||
| out_type = infer_pa_type(return_type) | ||
| input_types_sedona_db = infer_input_types(input_types) | ||
|
|
||
| @sedona_udf_module.arrow_udf(out_type, input_types=input_types_sedona_db) | ||
| def shapely_udf(*args, **kwargs): | ||
| return fn(*args, **kwargs) | ||
|
|
||
| udf = UserDefinedFunction( | ||
| lambda: shapely_udf, return_type, "SedonaPandasArrowUDF", evalType=eval_type | ||
| ) | ||
|
|
||
| return udf | ||
|
|
||
| return apply_fn | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had trouble integrating with Python 3.8, it's already one year since it reached EOL, what would you think about removing it? and maybe start supporting Python 3.12 and 3.13