Skip to main content

Language Bindings

GeoBrix exposes one function set across SQL and Python. The per-function reference lives on the package pages: RasterX, GridX, VectorX, and PMTiles. This page covers the names, registration and import pattern of each language. It also covers how SQL names resolve in a session and in Unity Catalog, and where the Scala JAR fits.

One function, three surfaces​

Every function has one canonical name. The surface decides only how you call it.

SurfaceFormExample
SQL (session)gbx_<name>gbx_rst_boundingbox(tile)
SQL (Unity Catalog)<catalog>.<schema>.gbx_<name>main.geobrix.gbx_bng_aswkb(cell)
Python<name> in a package modulerx.rst_boundingbox(tile)

The gbx_ prefix keeps GeoBrix functions apart from the Databricks built-in st_* functions. Python uses the bare rst_*, bng_*, quadbin_*, st_* and pmtiles_* names. The availability page shows which function runs on which surface.

Python​

Each package has one Python API. Import its functions module and call the bare names:

PackageImport
RasterXfrom databricks.labs.gbx.rasterx import functions as rx
GridX (BNG)from databricks.labs.gbx.gridx.bng import functions as bx
GridX (other grids)gridx.quadbin, gridx.custom, gridx.h3
VectorXfrom databricks.labs.gbx.vectorx import functions as vx
PMTilesfrom databricks.labs.gbx.pmtiles import functions as pm
from databricks.labs.gbx.rasterx import functions as rx

df.select(rx.rst_boundingbox("tile"))
  • The first call registers the function. You need no register(spark) for Python code. GeoBrix registers the name at the level the compute offers, then later calls cost nothing.
  • Wrappers take a Column or a scalar. Numbers, booleans and bytes are wrapped for you. A bare string follows PySpark's rule and names a column. Wrap a string literal in f.lit("...").
  • Table functions take the DataFrame. A generator returns many rows per input, so its wrapper takes the DataFrame first and returns a DataFrame: bx.bng_kringexplode(df, "cellid", 1). Pass argument columns by name. The wrapper refuses an input column that clashes with an output column, and the message gives the fix.
  • Some keywords exist only in Python. The tile functions take virtualize_dir, virtualize_prefix and materialize. A few functions take a trailing out_crs. SQL binds arguments by position, so these keywords have no SQL form. Each function section lists them.
  • Helpers live in helpers modules. Python-only helpers sit in databricks.labs.gbx.rasterx.helpers (merge_by_key, combine_by_key, mint_vrt, prepare_cogs, tile_to_numpy, rst_apply, rst_viewshed_towers, the *_grouped functions and others), vectorx.helpers and gridx.helpers. The pyrx, pygx and pyvx packages are internal.

SQL​

SQL functions exist only after registration. One call registers every function and the *_gbx data sources:

from databricks.labs.gbx import register

register(spark)
SELECT gbx_rst_width(tile) FROM rasters;

gbx.register(spark) returns the registered names with their levels. Use DESCRIBE FUNCTION EXTENDED gbx_rst_clip for a signature.

SQL binds arguments by position. A call with an extra argument drops it silently, so check a function's signature on its reference page. Generators are table functions: write FROM t, LATERAL gbx_...(args).

Session SQL and Unity Catalog SQL​

A name such as gbx_bng_aswkb can exist twice: as a session function and as a Unity Catalog function. The rules for which one runs:

  • A three-part name always runs the Unity Catalog function: main.geobrix.gbx_bng_aswkb(cell).
  • A bare name runs the session function when one is registered. The session path comes before the built-ins and the current schema.
  • A bare name reaches Unity Catalog only when no session function has that name and the schema is on the path.
  • GeoBrix never changes your path. SET PATH is your choice. The Unity Catalog page gives the statement.
  • Nothing warns you when a session function shadows a Unity Catalog one.

To see which one a name resolves to, run DESCRIBE FUNCTION EXTENDED. A session function shows a bare name. A Unity Catalog function shows the three-part name.

register(spark, catalog="main", schema="geobrix") checks that the schema's GeoBrix version matches the wheel. It prints one line when it does not. register(spark, target="uc", ...) registers no session function, so a notebook behaves as a SQL warehouse does.

Scala and the JAR​

Scala is the GeoBrix performance tier, not an API. The JAR adds a JVM level to some functions on a dedicated cluster. GeoBrix picks it where it is faster, so your SQL and Python calls use it with no change.

  • The JAR registers no SQL. register(spark) in Python registers every name, in the same session.
  • JVM code calls the SQL names. Scala or Java code on the session calls a function by name, for example call_function("gbx_rst_width", col("tile")). See SQL from a JVM job.
  • Functions the JAR speeds up lists the functions that run on the JVM. A function's Scala tag links there.

Next steps​