Skip to main content
Havasu supports geometry data type and allows users to use geometry functions in WherobotsDB for manipulating geometry data. This document describes how to use geometry data type and geometry functions in Havasu.

Geometry as a Primitive Type

Besides the primitive types supported by Apache Iceberg, Havasu introduced a new data type GEOMETRY to represent geospatial data. For instance, user can create a table with a geometry column using SQL:
This will create an empty table partitioned by the bucketed value of id. Notice that Havasu introduced a new data type GEOMETRY to represent geospatial data. We can inspect the table schema using DESCRIBE command:
Or using .printSchema() function:

Creating Table with Geometry Column

As mentioned above, user can create a Havasu table using SQL:
If user has a DataFrame containing geometry data, they can also create a Havasu table using the DataFrame:

Writing Data

INSERT INTO

User can insert data into a Havasu table using INSERT INTO table_name VALUES:
Or using INSERT INTO table_name SELECT ... to insert result set of a query into the table:

Writing DataFrame to Havasu table

User can write a DataFrame containing geometry data to a Havasu table:
This is semantically equivalent to the INSERT INTO table_name SELECT ... statement.

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

Data in columns with geometry type will be loaded as GeometryUDT values in Sedona, user can use any ST_ functions provided by WherobotsDB to manipulate the geospatial data. For example, user can use ST_Buffer to create a buffer around the geometry column:
The resulting DataFrame can also be written back to a Havasu table using a CTAS statement:
Or simply call writeTo function on the resulting DataFrame of the query:

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.