Skip to main content
Havasu supports the GEOMETRY and GEOGRAPHY data types and allows users to use the spatial functions in WherobotsDB for manipulating them. This document describes how to create, write, and query tables with geometry and geography columns.

Readable as geometry by other engines

The geometry type is recorded in the table schema and in the Parquet files, so an Apache Iceberg engine outside Wherobots that supports geospatial types sees a geometry column instead of a binary column it has to decode itself.

One CRS per column, enforced

A column carries exactly one Coordinate Reference System (CRS). A value whose Spatial Reference Identifier (SRID) disagrees with it is rejected instead of being stored under the wrong CRS.
org_catalog throughout this page is an example catalog name. Replace it with the name of the catalog you are writing to.

Creating Table with Geometry Column

Besides the primitive types supported by Apache Iceberg, Havasu has a GEOMETRY data type to represent geospatial data. Declare the column with its CRS in parentheses, as an SRID:
This will create an empty table partitioned by the bucketed value of id, with a geometry column in SRID 4326, which is World Geodetic System 1984 (WGS84) longitude and latitude. A geometry column requires a declared CRS: write geometry(4326), not geometry.
The column was declared as geometry with no CRS in parentheses. Add the SRID:
We can inspect the table schema using DESCRIBE command:
DESCRIBE TABLE shows the type as geometry without the CRS. To see the CRS, run SHOW CREATE TABLE, which renders the column as geom GEOMETRY(4326):
The statement SHOW CREATE TABLE returns recreates an equivalent table, so it is also the way to clone the schema of an existing table.
A geometry column created without a CRS, which is how tables were created before geometry(<srid>) was available, renders as geom GEOMETRY with no parentheses in SHOW CREATE TABLE. DESCRIBE TABLE shows geometry for both kinds of column. To see a table’s Apache Iceberg format version, run SHOW TBLPROPERTIES org_catalog.test_db.test_table ('format-version').Tables created without a CRS keep working: reads, spatial filter push-down, and every ST_ function behave the same. They do not check the SRID of written values, and other Iceberg engines read the column as binary. Wherobots upgrades the read-only public tables it manages, such as those in the wherobots_open_data catalog, automatically. To upgrade your own tables, see Upgrade Existing Geometry Tables.

Writing Data

INSERT INTO

User can insert data into a Havasu table using INSERT INTO table_name VALUES. Every value has to carry the SRID of the column:
Or using INSERT INTO table_name SELECT ... to insert result set of a query into the table:

Matching the column CRS

Geometry constructors such as ST_GeomFromText and ST_Point return SRID 0, which is a distinct CRS rather than “unset”, so a geometry(4326) column rejects it. Which function you need depends on the SRID your values already carry: ST_SetSRID relabels without touching the coordinates. Applying it to metre coordinates declares them as longitude and latitude, which puts the data in the wrong place. Use ST_Transform when the coordinates are in another CRS.
A value disagrees with the column CRS. The message names the fix:

Writing DataFrame to Havasu table

User can write a DataFrame containing geometry data to a Havasu table. The same SRID rule applies to the DataFrame’s values:
This is semantically equivalent to the INSERT INTO table_name SELECT ... statement.

Creating a table from a query or a DataFrame

CREATE TABLE ... AS SELECT and writeTo(...).create() create a table from the result of a query or a DataFrame. When the geometry comes from a geometry(<srid>) column read from a table, the new column has the same declared CRS. To choose the CRS of the new column yourself, for example for a geometry computed with an ST_ function, create the table with CREATE TABLE first and then write to it with INSERT INTO ... SELECT or writeTo(...).append(), as shown in Working with Geometry Data.

Updating data in Havasu table

Havasu supports UPDATE queries that update matching rows in tables. Update queries accept a filter to match rows to update. Spatial filters are also supported in Havasu.

Deleting data from Havasu table

Havasu supports DELETE FROM queries to remove data from tables. Delete queries accept a filter to match rows to delete. Spatial filters are also supported in Havasu.

Merging DataFrame into Havasu table using MERGE INTO

Havasu supports MERGE INTO by rewriting data files that contain rows that need to be updated in an overwrite commit. The syntax is identical to the open source Apache Iceberg, please refer to Apache Iceberg - MERGE INTO for more information.

Querying Data

User can load data from a Havasu table using sedona.table(...):
You can apply some configurations for reading the table, such as the split size if you want to read the table into a DataFrame with more partitions:
You can run spatial range query on the table using Spatial SQL:
Or using the DataFrame API:
Users can also load a Havasu table by specifying the name of the data source explicitly using .format("havasu.iceberg"), this will load an isolated table reference that will not automatically refresh tables used by queries.
Spatial range queries are very efficient in Havasu. Havasu supports spatial filter based data skipping. This feature allows user to skip reading data files that don’t contain data that satisfy the spatial filter. Please refer to Cluster by geospatial fields for faster queries for more information.

Working with Geometry Data

User can use any ST_ functions provided by WherobotsDB to manipulate the data in a geometry column. For example, user can use ST_Buffer to create a buffer around the geometry column:
To write the result back to a Havasu table, create the table with its geometry column first, then insert the result of the query. ST_Buffer keeps the SRID of its input, so the buffered values match a geometry(4326) column:
Or call writeTo(...).append() on the resulting DataFrame of the query:

Geography Columns

GEOGRAPHY(<srid>) interprets coordinates on a sphere rather than a plane, so ST_Distance, ST_Area, and ST_Length return spherical results in meters without projecting first.
A geography column rejects a value whose SRID is a different CRS, the same as a geometry column. Unlike a geometry column, it accepts a value with no SRID, such as the result of ST_GeogFromWKT without the SRID argument, and stores it under the column CRS. There is no cast from GEOMETRY to GEOGRAPHY; use ST_GeomToGeography to convert, and ST_GeogToGeometry in the other direction. See the geography function reference for the full list.

Further Reading

Havasu is based on Apache Iceberg, all features of Apache Iceberg except MOR tables are supported in Havasu. Please refer to Apache Iceberg documentation for Spark for more information. If you have spatial data stored in Iceberg table or parquet files as WKT or WKB, you can migrate your data to Havasu very efficiently without scanning or rewriting your data files. Please refer to Convert Existing Table to Havasu Table and Migrating Parquet Files to Havasu for more information. Havasu supports spatial filter push down and can optimize spatial range queries. Please refer to Cluster by geospatial fields for faster queries for how to organize your spatial data for better performance.