Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions docker/test-notebooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
# under the License.

set -e
# Without pipefail, a failing `python3 ... | tee ...` pipeline returns tee's
# (zero) exit status, so a notebook crash or timeout would be silently
# misreported as a pass. Enable pipefail so the per-notebook `if` block
# below sees the real exit code.
set -o pipefail

# Set up environment variables if not already set
export SPARK_HOME=${SPARK_HOME:-/opt/spark}
Expand Down Expand Up @@ -60,11 +65,26 @@ NOTEBOOK_COUNT=$(echo "$NOTEBOOK_FILES" | wc -l)
echo "Found $NOTEBOOK_COUNT notebook file(s) to test (root level only, excluding subdirectories)"
echo ""

SKIPPED_TESTS=0

# Convert and test each notebook
for NOTEBOOK in $NOTEBOOK_FILES; do
NOTEBOOK_NAME=$(basename "$NOTEBOOK" .ipynb)
PYTHON_FILE="${NOTEBOOK%.ipynb}.py"

# A notebook can declare a network dependency by including the marker
# requires-network: true
# anywhere in its source (typically in the first markdown cell). When
# SEDONA_NOTEBOOK_OFFLINE=1 is set, such notebooks are skipped so the
# harness still passes in sandboxed CI environments without outbound
# network access.
if [ "${SEDONA_NOTEBOOK_OFFLINE:-0}" = "1" ] && grep -q "requires-network: true" "$NOTEBOOK"; then
echo "Skipping (offline mode): $NOTEBOOK_NAME"
echo ""
SKIPPED_TESTS=$((SKIPPED_TESTS + 1))
continue
fi

echo "Testing: $NOTEBOOK_NAME"
echo " Converting notebook to Python..."

Expand Down Expand Up @@ -179,13 +199,15 @@ PYTHON_CLEANUP
continue
fi

# Run the full Python script with timeout (600 seconds = 10 minutes)
echo " Running Python script (600 second timeout)..."
# Run the full Python script with timeout (900 seconds = 15 minutes).
# Bumped from 600s to absorb network variance in notebooks that hit STAC
# or remote object stores. Local-data notebooks finish well under 60s.
echo " Running Python script (900 second timeout)..."
cd "$EXAMPLES_DIR/.."

# Use timeout with progress reporting
START_TIME=$(date +%s)
if timeout 600 python3 "$PYTHON_FILE" | tee /tmp/notebook_output_$$.log; then
if timeout 900 python3 "$PYTHON_FILE" | tee /tmp/notebook_output_$$.log; then
END_TIME=$(date +%s)
Comment thread
jiayuasu marked this conversation as resolved.
ELAPSED=$((END_TIME - START_TIME))
echo " ✓ Test passed (completed in ${ELAPSED}s)"
Expand All @@ -195,7 +217,7 @@ PYTHON_CLEANUP
END_TIME=$(date +%s)
ELAPSED=$((END_TIME - START_TIME))
if [ $EXIT_CODE -eq 124 ]; then
echo " ✗ Test timed out (exceeded 600 seconds, ran for ${ELAPSED}s)"
echo " ✗ Test timed out (exceeded 900 seconds, ran for ${ELAPSED}s)"
echo " Last 20 lines of output:"
tail -20 /tmp/notebook_output_$$.log 2>/dev/null || echo " (no output captured)"
else
Expand All @@ -213,9 +235,10 @@ done
echo "========================================="
echo "Test Summary"
echo "========================================="
echo "Passed: $PASSED_TESTS"
echo "Failed: $FAILED_TESTS"
echo "Total: $((PASSED_TESTS + FAILED_TESTS))"
echo "Passed: $PASSED_TESTS"
echo "Failed: $FAILED_TESTS"
echo "Skipped: $SKIPPED_TESTS"
echo "Total: $((PASSED_TESTS + FAILED_TESTS + SKIPPED_TESTS))"
echo "========================================="

if [ $FAILED_TESTS -gt 0 ]; then
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ SedonaPyDeck.create_choropleth_map(df=groupedresult, plot_col="AirportCount")
![Creating a Choropleth map using SedonaPyDeck](../image/choropleth.gif)

The dataset used is available [here](https://github.com/apache/sedona/tree/b66e768155866a38ba2e3404f1151cac14fad5ea/docs/usecases/data/ne_50m_airports) and
can also be found in the example notebook available [here](https://github.com/apache/sedona/blob/master/docs/usecases/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb)
can also be found in the example notebook available [here](https://github.com/apache/sedona/blob/master/docs/usecases/legacy/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb)

#### Creating a Geometry map using SedonaPyDeck

Expand Down Expand Up @@ -923,7 +923,7 @@ SedonaKepler.create_map(df=groupedresult, name="AirportCount")
![Visualize geospatial data using SedonaKepler](../image/sedona_customization.gif)

The dataset used is available [here](https://github.com/apache/sedona/tree/b66e768155866a38ba2e3404f1151cac14fad5ea/docs/usecases/data/ne_50m_airports) and
can also be found in the example notebook available [here](https://github.com/apache/sedona/blob/master/docs/usecases/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb)
can also be found in the example notebook available [here](https://github.com/apache/sedona/blob/master/docs/usecases/legacy/ApacheSedonaSQL_SpatialJoin_AirportsPerCountry.ipynb)

Details on all the APIs available by SedonaKepler are listed in the [SedonaKepler API docs](../api/sql/Visualization-SedonaKepler.md)

Expand Down
170 changes: 170 additions & 0 deletions docs/usecases/00-quickstart.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": "<!--\n Licensed to the Apache Software Foundation (ASF) under one\n or more contributor license agreements. See the NOTICE file\n distributed with this work for additional information\n regarding copyright ownership. The ASF licenses this file\n to you under the Apache License, Version 2.0 (the\n \"License\"); you may not use this file except in compliance\n with the License. You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing,\n software distributed under the License is distributed on an\n \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n KIND, either express or implied. See the License for the\n specific language governing permissions and limitations\n under the License.\n-->\n\n# Sedona quickstart\n\nA short, end-to-end spatial workflow. We answer:\n\n> **Which countries have the most airports per million people?**\n\nAlong the way we read two shapefiles, run a distributed spatial join, aggregate, write **GeoParquet 1.1** with auto covering-bbox metadata, read it back, and render an interactive map with **SedonaKepler**.\n\nData ships with the docker image (Natural Earth 50m admin and airports). No network required.\n\nMore use-case notebooks (vector at scale, raster pipelines, raster + vector fusion, STAC, GeoPandas-on-Spark) will land alongside this one as the docker examples are refreshed for the 1.9.x series."
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from sedona.spark import SedonaContext\n",
"\n",
"config = SedonaContext.builder().master(\"spark://localhost:7077\").getOrCreate()\n",
"sedona = SedonaContext.create(config)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Read country polygons. The shapefile reader is a first-class Spark V2 datasource\n",
"# in Sedona; no manual binary parsing.\n",
"countries = (\n",
" sedona.read.format(\"shapefile\")\n",
" .load(\"data/ne_50m_admin_0_countries_lakes\")\n",
" .selectExpr(\n",
" \"geometry\",\n",
" \"NAME as country\",\n",
" \"CONTINENT as continent\",\n",
" \"POP_EST as population\",\n",
" )\n",
")\n",
"countries.show(5, truncate=40)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"airports = (\n",
" sedona.read.format(\"shapefile\")\n",
" .load(\"data/ne_50m_airports\")\n",
" .selectExpr(\n",
" \"geometry\",\n",
" \"name as airport\",\n",
" \"type as airport_type\",\n",
" )\n",
")\n",
"airports.show(5, truncate=40)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Spatial join: which country contains each airport?\n",
"# Sedona inserts a broadcast spatial index when one side is small.\n",
"airports.createOrReplaceTempView(\"airports\")\n",
"countries.createOrReplaceTempView(\"countries\")\n",
"\n",
"joined = sedona.sql(\"\"\"\n",
" SELECT c.country, c.continent, c.population, a.airport\n",
" FROM countries c\n",
" JOIN airports a ON ST_Contains(c.geometry, a.geometry)\n",
"\"\"\")\n",
"joined.show(5, truncate=40)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Rank countries by airports per million people.\n",
"joined.createOrReplaceTempView(\"joined\")\n",
"\n",
"ranked = sedona.sql(\"\"\"\n",
" SELECT\n",
" country,\n",
" continent,\n",
" population,\n",
" COUNT(*) AS airport_count,\n",
" ROUND(COUNT(*) * 1e6 / NULLIF(population, 0), 2) AS airports_per_million\n",
" FROM joined\n",
" WHERE population > 1000000\n",
" GROUP BY country, continent, population\n",
" ORDER BY airports_per_million DESC\n",
"\"\"\")\n",
"ranked.show(10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Attach the rank back onto country geometries and write GeoParquet 1.1.\n",
"# Sedona auto-populates the covering-bbox metadata and projjson CRS from the\n",
"# geometry SRID, so downstream readers can prune partitions efficiently.\n",
"import os\n",
"import shutil\n",
"\n",
"ranked.createOrReplaceTempView(\"ranked\")\n",
"ranked_geo = sedona.sql(\"\"\"\n",
" SELECT c.country, c.continent,\n",
" r.airport_count, r.airports_per_million,\n",
" c.geometry\n",
" FROM ranked r\n",
" JOIN countries c USING (country)\n",
"\"\"\")\n",
"\n",
"out_path = \"/tmp/airports_per_country.parquet\"\n",
"if os.path.exists(out_path):\n",
" shutil.rmtree(out_path)\n",
"ranked_geo.coalesce(1).write.format(\"geoparquet\").save(out_path)\n",
"\n",
"sedona.read.format(\"geoparquet\").load(out_path).show(5, truncate=40)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from sedona.spark import SedonaKepler\n",
"\n",
"ranked_geo_df = sedona.read.format(\"geoparquet\").load(out_path)\n",
"SedonaKepler.create_map(df=ranked_geo_df, name=\"airports_per_million\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": "## What just happened?\n\nIn a handful of cells we ran an end-to-end spatial workflow:\n\n1. **Read** two shapefiles directly into Spark DataFrames via Sedona's V2 shapefile datasource.\n2. **Joined** them spatially with `ST_Contains` — Sedona inserts a broadcast spatial index automatically when one side is small.\n3. **Aggregated and ranked** countries by airports per capita.\n4. **Wrote** the result as **GeoParquet 1.1**; covering-bbox metadata and projjson CRS were populated automatically from the geometry SRID. Downstream readers can prune to a bounding box without scanning every row.\n5. **Rendered** an interactive choropleth with **SedonaKepler**.\n\nThe exact same code path scales to billions of rows on a real Spark cluster — no API change, just more workers."
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading