martin-g commented on code in PR #238:
URL: https://github.com/apache/sedona-db/pull/238#discussion_r2471021271


##########
docs/delta-lake.md:
##########
@@ -0,0 +1,202 @@
+<!---
+  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.
+-->
+
+# SedonaDB + Delta Lake
+
+This page shows how to read and write Delta Lake tables with SedonaDB.
+
+Make sure you run `pip install deltalake` to run the cells in this notebook.
+
+
+```python
+from deltalake import write_deltalake, DeltaTable
+import sedona.db
+
+sd = sedona.db.connect()
+```
+
+Read in a GeoParquet dataset into a SedonaDB DataFrame.
+
+
+```python
+countries = sd.read_parquet(
+    
"https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_countries_geo.parquet";
+)
+```
+
+## Create a Delta Lake table
+
+Now write the DataFrame to a Delta Lake table.  Notice that you must convert 
the geometry column to Well-Known Text (WKT) before writing to the Delta table.
+
+Delta Lake does not support geometry columns.
+
+
+```python
+countries.to_view("countries", True)
+df = sd.sql(
+    "select name, continent, ST_AsText(geometry) as geometry_wkt from 
countries"
+)
+table_path = "/tmp/delta_with_wkt"
+write_deltalake(table_path, df.to_pandas(), mode="overwrite")
+```
+
+## Read Delta table into SedonaDB
+
+Now read the Delta table back into a SedonaDB DataFrame.
+
+
+```python
+dt = DeltaTable(table_path)
+arrow_table = dt.to_pyarrow_table()
+df = sd.create_data_frame(arrow_table)
+df.show()
+```
+
+    
┌─────────────────────────────┬───────────────┬────────────────────────────────────────────────────┐
+    │             name            ┆   continent   ┆                    
geometry_wkt                    │
+    │             utf8            ┆      utf8     ┆                        
utf8                        │
+    
╞═════════════════════════════╪═══════════════╪════════════════════════════════════════════════════╡
+    │ Fiji                        ┆ Oceania       ┆ MULTIPOLYGON(((180 
-16.067132663642447,180 -16.55… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ United Republic of Tanzania ┆ Africa        ┆ POLYGON((33.90371119710453 
-0.9500000000000001,34… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Western Sahara              ┆ Africa        ┆ 
POLYGON((-8.665589565454809 27.656425889592356,-8… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Canada                      ┆ North America ┆ 
MULTIPOLYGON(((-122.84000000000003 49.00000000000… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ United States of America    ┆ North America ┆ 
MULTIPOLYGON(((-122.84000000000003 49.00000000000… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Kazakhstan                  ┆ Asia          ┆ POLYGON((87.35997033076265 
49.21498078062912,86.5… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Uzbekistan                  ┆ Asia          ┆ POLYGON((55.96819135928291 
41.30864166926936,55.9… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Papua New Guinea            ┆ Oceania       ┆ 
MULTIPOLYGON(((141.00021040259185 -2.600151055515… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Indonesia                   ┆ Asia          ┆ 
MULTIPOLYGON(((141.00021040259185 -2.600151055515… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Argentina                   ┆ South America ┆ 
MULTIPOLYGON(((-68.63401022758323 -52.63637045887… │
+    
└─────────────────────────────┴───────────────┴────────────────────────────────────────────────────┘
+
+
+Notice that the `geometry_wkt` column is `utf8`.  It's not a geometry column.
+
+Let's convert the `geometry_wkt` column to a geometry column.
+
+
+```python
+df.to_view("my_table", True)
+res = sd.sql("""
+SELECT
+  name,
+  continent,
+  ST_GeomFromWKT(geometry_wkt) as geom
+from my_table
+""")
+res.show()
+```
+
+    
┌─────────────────────────────┬───────────────┬────────────────────────────────────────────────────┐
+    │             name            ┆   continent   ┆                        
geom                        │
+    │             utf8            ┆      utf8     ┆                      
geometry                      │
+    
╞═════════════════════════════╪═══════════════╪════════════════════════════════════════════════════╡
+    │ Fiji                        ┆ Oceania       ┆ MULTIPOLYGON(((180 
-16.067132663642447,180 -16.55… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ United Republic of Tanzania ┆ Africa        ┆ POLYGON((33.90371119710453 
-0.9500000000000001,34… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Western Sahara              ┆ Africa        ┆ 
POLYGON((-8.665589565454809 27.656425889592356,-8… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Canada                      ┆ North America ┆ 
MULTIPOLYGON(((-122.84000000000003 49.00000000000… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ United States of America    ┆ North America ┆ 
MULTIPOLYGON(((-122.84000000000003 49.00000000000… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Kazakhstan                  ┆ Asia          ┆ POLYGON((87.35997033076265 
49.21498078062912,86.5… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Uzbekistan                  ┆ Asia          ┆ POLYGON((55.96819135928291 
41.30864166926936,55.9… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Papua New Guinea            ┆ Oceania       ┆ 
MULTIPOLYGON(((141.00021040259185 -2.600151055515… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Indonesia                   ┆ Asia          ┆ 
MULTIPOLYGON(((141.00021040259185 -2.600151055515… │
+    
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+    │ Argentina                   ┆ South America ┆ 
MULTIPOLYGON(((-68.63401022758323 -52.63637045887… │
+    
└─────────────────────────────┴───────────────┴────────────────────────────────────────────────────┘
+
+
+Confirm the schema of the DataFrame.
+
+
+```python
+res.schema
+```
+
+
+
+
+    SedonaSchema with 3 fields:
+      name: utf8<Utf8>
+      continent: utf8<Utf8>
+      geom: geometry<Wkb>
+
+
+
+## Filter countries in a particular geographic region
+
+Now, let's grab all the countries in the western half of South America using a 
polygon region.
+
+SedonaDB can run these types of queries on geometric data.
+
+
+```python
+res = sd.sql("""
+SELECT
+  name,
+  continent,
+  ST_GeomFromWKT(geometry_wkt) as geom
+FROM my_table
+WHERE ST_Intersects(
+  ST_GeomFromWKT(geometry_wkt),

Review Comment:
   educational question: could we use `geom` here instead?



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