Query FeatureQL through ADBC
featuremesh-adbc runs FeatureQL from Python code that already uses ADBC , Arrow's database connectivity API. You write FeatureQL, and you get Arrow tables or data frames back. In the transpiled mode, your own database runs the query and only the translation happens on a FeatureMesh server.
pip install featuremesh-adbc duckdb # DuckDB's ADBC driver ships in the duckdb package It needs Python 3.12 or later and the ADBC driver of your database. The driver name you pass to connect() picks it:
| Database | driver | Install the driver with |
|---|---|---|
| DuckDB | duckdb | pip install duckdb (the driver ships inside it) |
| PostgreSQL | postgresql | pip install adbc-driver-postgresql |
| BigQuery | bigquery | pip install adbc-driver-bigquery |
| Snowflake | snowflake | pip install adbc-driver-snowflake |
| featuremeshd | flightsql | pip install adbc-driver-flightsql |
| Trino, ClickHouse, Databricks | trino, clickhouse, databricks | dbc install <driver> ( dbc , Columnar's ADBC driver installer: these have no pip package) |
The package page on PyPI shows a connect() call for each database. The transpiled mode works with a FeatureMesh registry 0.4.1 or later; the direct mode needs featuremeshd 0.3.1 or later.
Run FeatureQL on your database
In the transpiled mode, the package sends each statement to the registry, receives the SQL for your database, and runs that SQL through the ADBC driver:
from featuremesh_adbc import dbapi
config = {
"adbc.featuremesh.execution_mode": "transpiled",
"adbc.featuremesh.registry_url": "https://<your registry>/v1/featureql",
"adbc.featuremesh.registry_token": "<your token>",
}
with dbapi.connect(driver="duckdb", path=":memory:", **config) as con, con.cursor() as cursor:
cursor.execute("RETURN F1 := 1, F2 := 2, F3 := F1 + F2;")
table = cursor.fetch_arrow_table()
assert tuple(table.to_pylist()[0].values()) == (1, 2, 3) The registry translates for the database the driver names: duckdb here. Set adbc.featuremesh.backend when the two differ. cursor.fetch_df() returns a pandas data frame instead, when pandas is installed.
Send FeatureQL to featuremeshd
In the direct mode, the default, the package passes each statement unchanged to the driver. Use it with the Flight SQL driver (pip install adbc-driver-flightsql) against the Flight SQL port of featuremeshd 0.3.1 or later, which reads FeatureQL itself. featuremeshd checks every caller: send a project user or service account token in the Authorization header:
from featuremesh_adbc import dbapi
auth = {"adbc.flight.sql.authorization_header": "Bearer <your token>"}
with dbapi.connect(driver="flightsql", uri="grpc://<featuremeshd host>:10093", **auth) as con, con.cursor() as cursor:
cursor.execute("RETURN F1 := 1, F2 := 2, F3 := F1 + F2;")
table = cursor.fetch_arrow_table()
assert tuple(table.to_pylist()[0].values()) == (1, 2, 3) Options
| Option | Values | Default |
|---|---|---|
adbc.featuremesh.execution_mode | direct: the statement goes to the driver unchanged. transpiled: the registry translates it first | direct |
adbc.featuremesh.registry_url | The registry's FeatureQL endpoint. Required in the transpiled mode | — |
adbc.featuremesh.registry_token | Your registry token. Required in the transpiled mode | — |
adbc.featuremesh.backend | The backend the registry translates for | the driver's name |
adbc.featuremesh.debug | True prints the SQL the registry returned | False |
When a statement is refused
The cursor runs one SQL statement per call. A FeatureQL statement whose translation needs several steps, such as temporary tables created first, is refused with the named error PLAN-NEEDS-STEPS. Run it with the Python library instead, which runs every step.
A registry newer than the package can answer with a plan the package does not know. It refuses it with PLAN-VERSION-UNSUPPORTED or PLAN-UNKNOWN-VALUE before running anything: upgrade the package.
Related
- Python library : the full client, with Jupyter magic and every step of a translation.
- Persisted views : a stable table for tools that speak SQL only.