-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spark): add Apache Sedona (#11527)
- Loading branch information
1 parent
0f4bf97
commit 1c4b314
Showing
13 changed files
with
334 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
openjdk-install: | ||
brew install openjdk@17 | ||
apache-spark-install: | ||
brew install apache-spark | ||
sbt-install: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
poetry-env-use: | ||
poetry env use 3.11 | ||
poetry-update-lock-file: | ||
poetry lock --no-update | ||
poetry-install: | ||
poetry install --no-root | ||
poetry-add: | ||
poetry add xxx | ||
poetry-add-dev: | ||
poetry add xxx --group=dev | ||
|
||
poetry-run-dev: | ||
poetry run poe dev |
Empty file.
239 changes: 239 additions & 0 deletions
239
hm-spark/applications/analyze-coffee-customers/poetry.lock
Large diffs are not rendered by default.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
hm-spark/applications/analyze-coffee-customers/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[tool.poetry] | ||
name = "hm-spark-analyze-coffee-customers" | ||
version = "1.0.0" | ||
description = "" | ||
authors = ["Hongbo Miao"] | ||
|
||
[tool.poetry.dependencies] | ||
python = "3.11.x" | ||
apache-sedona = {version = "1.4.1", extras = ["spark"]} | ||
|
||
[tool.poetry.group.dev.dependencies] | ||
poethepoet = "0.23.0" | ||
|
||
[build-system] | ||
requires = ["poetry-core"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.poe.tasks] | ||
dev = "python src/main.py" |
53 changes: 53 additions & 0 deletions
53
hm-spark/applications/analyze-coffee-customers/src/main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from sedona.spark import SedonaContext | ||
|
||
|
||
def main() -> None: | ||
sedona_config = ( | ||
SedonaContext.builder() | ||
.config( | ||
"spark.jars.packages", | ||
# https://mvnrepository.https://mvnrepository.com/artifact/org.apache.sedona | ||
"org.apache.sedona:sedona-spark-shaded-3.4_2.12:1.4.1," | ||
# https://mvnrepository.com/artifact/org.datasyslab/geotools-wrapper | ||
"org.datasyslab:geotools-wrapper:1.4.0-28.2", | ||
) | ||
.getOrCreate() | ||
) | ||
sedona = SedonaContext.create(sedona_config) | ||
|
||
( | ||
sedona.read.format("csv") | ||
.option("delimiter", ",") | ||
.option("header", "false") | ||
# https://github.com/apache/sedona/blob/master/binder/data/testpoint.csv | ||
.load("data/testpoint.csv") | ||
).createOrReplaceTempView("points") | ||
|
||
sedona.sql( | ||
""" | ||
select st_point(cast(points._c0 as double), cast(points._c1 as double)) as point | ||
from points | ||
""" | ||
).createOrReplaceTempView("points1") | ||
sedona.sql( | ||
""" | ||
select st_point(cast(points._c0 as double), cast(points._c1 as double)) as point | ||
from points | ||
""" | ||
).createOrReplaceTempView("points2") | ||
|
||
df = sedona.sql( | ||
""" | ||
select | ||
points1.point as point1, | ||
points2.point as point2, | ||
st_distance(points1.point, points2.point) as distance | ||
from points1, points2 | ||
where st_distance(points1.point, points2.point) < 2 | ||
""" | ||
) | ||
df.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters