Surfaces & Levels
These docs use two short names. Lightweight means the Python level, without the JVM. Heavyweight means the JVM level, which needs the JAR. Neither is an install you pick or a separate API. See The levels.
GeoBrix has one function set. You choose a surface: where you call a function from. GeoBrix chooses the level: which implementation runs it.
You never pick a level. The compute decides, and GeoBrix says why when it falls back to another level.
The surfaces
| Surface | Form | Use it for | Runs on |
|---|---|---|---|
| SQL (session) | gbx_* after register(spark) | Notebooks, jobs and pipelines | Every compute except a SQL warehouse |
| SQL (Unity Catalog) | <catalog>.<schema>.gbx_* after gbx.uc.install | Warehouses, dashboards, governed and ad-hoc SQL | SQL warehouses, and any compute through a three-part name |
| Python | rasterx, gridx.<grid>, vectorx, pmtiles | DataFrame code, readers, writers and helpers | Every compute except a SQL warehouse |
A function has the same name on the SQL surfaces. The Python names drop the gbx_ prefix.
Scala code on dedicated compute calls the same names, through spark.sql or the Column wrappers. See SQL from a JVM job.
The GeoBrix JAR is a performance add-on that dedicated compute can load. It adds a JVM level to some functions, and GeoBrix picks it where it is faster. A function's Scala tag links to Functions the JAR speeds up.
Not every function exists on every surface. The availability page lists each function and the surfaces it runs on. Each function section shows the same badges.
A name that exists on both SQL surfaces takes the same arguments and gives the same result. Where a UC function differs, the Unity Catalog page says how.
One registrar
Call register once per session:
from databricks.labs.gbx import register
register(spark) # every gbx_* SQL function and every *_gbx reader and writer
- The call registers the functions and the
*_gbxdata sources. - The Python API also registers a function on its first call, so
register(spark)is optional for Python-only code. - The JAR registers no SQL. See Functions the JAR speeds up.
- The old per-package
registercalls (rasterx.functions.registerand the like) raise an error. The message gives the fix.
Pass only= to register a subset. Names are case-insensitive and take the SQL name or the short name.
register(spark, only=["rst_slope", "rst_clip"]) # just these two
A name that no function matches raises a ValueError. only=[] registers nothing.
The levels
A level is one implementation of a function. A function has one to four levels.
| Level | Name | What runs | Where it is available |
|---|---|---|---|
| L0 | SQL expression | Built-in Spark SQL: no UDF, no JAR and no Python | Sessions that can create a SQL function: dedicated and standard clusters |
| L1 | JVM | The JAR's Catalyst expressions (Scala and GDAL) | Dedicated clusters with the GeoBrix JAR |
| L3 | Python | A Python UDF (rasterio, NumPy, Shapely and the other libraries named in each function's note), sometimes with a Rust kernel inside | Everywhere the env wheel installs: Serverless, standard, dedicated, Lakeflow pipelines and the UC sandbox |
| L4 | Unity Catalog function | A SQL, Python or Scala function in a catalog | SQL warehouses, and any compute through a three-part name |
Every function has a Python level, so the wheel alone runs the whole library. The JAR adds the JVM level where it is faster. A few functions also have a SQL expression level. The Unity Catalog page covers L4.
A surface and a level are separate choices. For example, you call gbx_bng_eastnorthasbng from SQL or from Python. It runs as a SQL expression where the session allows one, and at the Python level elsewhere. These docs write L0 as "SQL expression", so that it does not read as the SQL surface.
Rust kernels in the Python level
Inside the Python level, GeoBrix picks a function's fastest form: a Rust kernel, then Arrow batches, then row by row. Rust kernels exist for two jobs:
- BNG cell encoding, behind
gbx_bng_eastnorthasbng. - TIN triangulation, behind
gbx_st_triangulate,gbx_st_interpolateelevationbboxandgbx_st_interpolateelevationgeom. It is a Rust port of JTS 1.20 and gives the JVM level's triangles.
The env wheel carries the Rust module, so there is nothing to install. If the module cannot load, GeoBrix runs the pure-Python form. Performance has the numbers. GeoBrix continues to assess where Rust can help further.
How GeoBrix picks a level
The wheel ships a table that lists, for each function, the levels to try and in what order. The order comes from measurements. A function with no measurement yet runs at L3, except a few that Functions the JAR speeds up lists.
For each function, register takes the first level that works on this compute. It skips a level when the JAR is missing, when the session is Spark Connect, or when a library is absent.
Most functions run on L3. Raster tile operations default to L3, because the Python implementation measured as fast or faster, or because the JVM form cannot read a virtual tile. Functions the JAR speeds up lists every function that picks L1 on a dedicated cluster with the JAR.
GeoBrix says why
When a faster level cannot run, register prints one line that names the level and the reason. A reason that applies to several functions prints once, with a count. Each line prints once per session.
geobrix: JVM level unavailable: Spark Connect session (standard access mode); using the Python level
register returns a dictionary of the level it chose for each name. Use it to check a session:
chosen = register(spark)
chosen["gbx_bng_eastnorthasbng"].level # 'L0' (SQL expression) or 'L3' (Python)
A name that no level can serve on this compute is skipped, with a line that says why. The other names still register.
Generators are table functions
A generator returns many rows for each input. Call it as a table function:
SELECT gbx_out.*
FROM my_cells AS t, LATERAL gbx_bng_kringexplode(t.cellid, 1) AS gbx_out
This form works on every compute and at every level. Do not call a generator in the select list or with LATERAL VIEW: a Python table function does not resolve there.
Where the JAR helps
Install the JAR only when you want the JVM level on a dedicated cluster. The wheel works alone everywhere.
- Dedicated clusters can use the env wheel and the JAR as cluster libraries, or a DCS image. See Choose an install path.
databricks.labs.gbx.stage_jar(vol_dir)copies the wheel's JAR to a Volume folder.- A cluster runs one GeoBrix JAR.
stage_jarrefuses a second JAR in the same Volume folder, with a fix. - Serverless cannot load the JAR, so it runs L3 and L4. A SQL warehouse runs L4 only.
Functions the JAR speeds up lists the functions that run on the JVM. For measured differences between levels, see Performance & Benchmarking.
What needs dedicated compute
Almost everything runs on every compute through the wheel. These features need more:
The GeoBrix DCS image pre-packages everything the JVM level needs. It holds the env6 wheel, the GeoBrix JAR, and native GDAL, PROJ and GEOS with GDAL's Java bindings. The cluster needs no libraries and no init script.
Limits today:
- It runs on dedicated access mode on DBR 19 only, for Graviton (arm64) and x86.
- There is no DBR 17.3 or 18 image. Install the env5 wheel and the JAR as cluster libraries.
- GeoBrix recommends it for dedicated access mode only today. On standard access mode and Serverless, use the env wheel. Standard and Serverless support is coming soon.
- The image passes its in-image checks but has not yet run on a cluster. The env wheel and JAR route is the one verified on clusters.
- STAC search and the sample-data downloaders are not in the image. Add them with
%pip, as the DCS page describes.
| Feature | Dedicated cluster | Standard access mode | Serverless | SQL warehouse |
|---|---|---|---|---|
| Every function at its Python level (L3), readers and writers | Yes | Yes | Yes | No (use UC functions) |
| The JVM level (L1): Functions the JAR speeds up | Yes, with the DCS image or the JAR | No. GeoBrix runs the Python level and says why | No | No |
| UC functions | Yes | Yes | Yes | Yes |
The Scala form of three UC grid functions (gbx_bng_kring, gbx_bng_aswkb, gbx_bng_centroid) | Not verified | Not verified | Not verified | Yes |
gbx_rst_merge_tvf and gbx_rst_bng_rasterize_tvf (TABLE(...) PARTITION BY) | Yes | Yes | No. Use gbx_rst_merge_agg and gbx_rst_bng_rasterize_agg | No |
Zarr access="direct" | Yes | No | No | No |
- JAR on standard access mode. The JAR is a cluster library only when a metastore admin has allowed its path. Even then GeoBrix uses the Python level, and it does not add the JAR to the session. A Serverless session never loads the JAR.
- UC Scala functions.
gbx.uc.installmakesgbx_bng_kring,gbx_bng_aswkbandgbx_bng_centroidScala functions when the install folder holds the JAR of the wheel's version. Without it they are Python functions with the same answers.gbx_bng_eastnorthasbngandgbx_bng_cellareaare always SQL functions. Scala functions on UC are verified on a SQL warehouse only. See Unity Catalog functions. - Zarr
access="auto"reads and writes through the Volume mount where direct access is not available. Only an explicit"direct"raises, with a fix. - A refusal names the compute that can run the feature, and a fix.
Virtual tiles and the JVM level
A virtual tile has no raster bytes. It holds a path and a window, and a Python worker reads it lazily. A materialized tile carries the encoded raster in its raster field. See Virtual tiles.
The JVM level reads bytes only. In SQL, GeoBrix routes the two kinds for you:
- A virtual tile goes to the Python implementation.
- A materialized tile goes to the JVM implementation, when the JVM level is the chosen one.
- An error tile comes out unchanged at every level.
Functions the JAR speeds up lists the functions that run on the JVM by default. It also marks the ones that route a virtual tile to Python.
The accessors and statistics that return an ARRAY<...>, a MAP<...> or a STRUCT<...> (gbx_rst_avg, gbx_rst_georeference and the like) have no JVM form and run at the Python level. Spark refuses a routing SQL function placed directly under explode or inline (UNSUPPORTED_SQL_UDF_USAGE). gbx_rst_avg is one. Compute the array in a subquery, then explode or inline the column.
The Python tile functions take three optional keywords: virtualize_dir, virtualize_prefix and materialize. SQL has none of them. See the force-output parameters.
Virtual and materialized advice
Ask which operations need pixels and which can stay lazy.
| Operation type | Behavior on a virtual tile | Notes |
|---|---|---|
Metadata accessors (rst_width, rst_height, rst_srid, rst_boundingbox, rst_format, rst_georeference, rst_metadata, rst_rotation, rst_scalex, rst_scaley, rst_skewx, rst_skewy, rst_numbands, rst_type, rst_getnodata, rst_upperleftx, rst_upperlefty) | Free. No pixels are read | The header opens lazily |
Pixel accessors and statistics (rst_avg, rst_min, rst_max, rst_median, rst_pixelcount, rst_summary, rst_histogram, rst_sample, rst_isempty) | Read the window, then return a scalar or array | Pixels are held only for the computation |
Reference and passthrough operations (rst_clip, rst_setsrid, rst_initnodata, rst_band, and rst_transform to the tile's own CRS) | Record an instruction or a region. No new pixels | The instruction applies at the next read. virtualize_dir has no effect |
Pixel-producing operations (slope, aspect, hillshade, terrain, focal, map algebra, spectral indices, rasterize, resample, rst_transform to another CRS, rst_merge, rst_combineavg, rst_frombands) | Materialize and return bytes | Pass virtualize_dir to write the result to a durable path and get a virtual tile |
Writers (raster_gbx, gtiff_gbx, cog_gbx) | Always materialize | A virtual DataFrame is directly writable. cog_gbx converts whole-file virtual tiles path-direct |
Short rule: chain deferrable operations as long as you like. Materialize when you need pixels.
Next steps
- Language bindings: the registration and import patterns of each language
- Availability: every function by surface
- Unity Catalog functions: the governed SQL slice
- Performance & Benchmarking: measured behavior by level