You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- backend.py: add _find_managed_connection helper that returns None for not-found
vs raising IbisError; use it in create_database so real 5xx API failures are no
longer swallowed by the broad `except IbisError: pass`
- backend.py: always overwrite _database_id in _table_location (drop the `or`) so
both cached fields stay in sync when multiple managed databases are used
- backend.py: add explicit parens to api_conn ternary in get_schema for clarity
- backend.py: document the database_id parameter in do_connect docstring
- README.md: rewrite as user-facing docs — quick start first, plain language,
no private method calls in examples, support table replaces spec-style prose
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Experimental[Ibis](https://ibis-project.org/)backend for [Hotdata](https://www.hotdata.dev/docs/api-reference): compile expressions with Ibis, run federated SQL over the Hotdata API. REST calls use the official **[hotdata](https://github.com/hotdata-dev/sdk-python)**Python SDK. Repo examples use **httpx** (listed under the **dev** dependency group).
3
+
Use[Ibis](https://ibis-project.org/)to query and upload data in your [Hotdata](https://www.hotdata.dev/docs/api-reference) workspace — write Python expressions instead of SQL, get pandas or Arrow results back.
-**Ibis connection API** — connect with `ibis.hotdata.connect(...)` or `ibis.connect("hotdata://...")`.
17
-
-**Hotdata catalog mapping** — expose Hotdata connections, schemas, and tables through Ibis catalogs, databases, and tables.
18
-
-**SQL-backed expression execution** — compile Ibis expressions with the Postgres SQLGlot compiler and execute them through Hotdata query APIs.
19
-
-**Typed table discovery** — load schema metadata from Hotdata information schema and map SQL types into Ibis types. Both SQL-style names (`INTEGER`, `VARCHAR`) and Arrow-style names (`Float64`, `Utf8`) returned by Parquet/managed tables are handled.
20
-
-**Arrow and pandas results** — materialize expressions as pandas DataFrames, PyArrow tables, or local Arrow record batches.
21
-
-**Raw SQL escape hatch** — use `con.sql(..., dialect="postgres")` when Hotdata-specific federated SQL is clearer than modeled Ibis expressions.
22
-
-**Managed database writes** — create managed connections with `create_database`, load local pandas or PyArrow data through `create_table`, and clean up with `drop_table` / `drop_database`.
16
+
```python
17
+
import ibis
23
18
24
-
## Connect
19
+
con = ibis.hotdata.connect(
20
+
api_url="https://api.hotdata.dev",
21
+
token="YOUR_API_TOKEN",
22
+
workspace_id="ws_…",
23
+
)
25
24
26
-
Programmatic API:
25
+
# List available tables
26
+
con.list_tables()
27
27
28
-
```python
29
-
import ibis
28
+
# Query with Ibis expressions
29
+
t = con.table("customer", database=("my_connection", "tpch_sf1"))
con = ibis.connect("hotdata://api.hotdata.dev/?token=…&workspace_id=ws_…")
51
59
```
52
60
53
-
**Mapping:**Ibis **catalog** = Hotdata connection id; **database** = remote schema; **table** = table name. SQL references look like `connection.schema.table`. With a single connection and schema, defaults are inferred; otherwise set `default_connection` / `default_schema`or qualify `con.table(..., database=(conn_id, schema))`.
61
+
**Table addressing:**Hotdata organizes data as `connection → schema → table`. In Ibis terms that maps to `catalog → database → table`. With a single connection and schema, defaults are inferred automatically. For multiple connections or schemas, pass `database=(connection_id, schema)` when referencing a table, or set `default_connection` / `default_schema` at connect time.
54
62
55
-
> **Managed databases:** SQL and Ibis expressions against managed database tables use `"default"` as the catalog rather than the connection id. The backend resolves this automatically — see [Managed databases](#managed-databases) below.
63
+
## Querying
56
64
57
-
**Execution:** SQL is compiled with Ibis’s **Postgres** SQLGlot compiler. The client submits queries asynchronously with `POST /v1/query`, polls `GET /v1/query-runs/{id}`, then downloads ready results as Arrow IPC from `GET /v1/results/{id}`. Tuning: `poll_interval_s`, `poll_timeout_s` on `connect()`.
65
+
### Ibis expressions
58
66
59
-
**Types:** Typed tables come from Hotdata’s information schema. `con.sql(...)` types are inferred from a small preview query and Arrow schema. Both SQL-style names (`INTEGER`, `DOUBLE PRECISION`) and Arrow-style names (`Float64`, `Utf8`, `Date32`) returned by Parquet/managed tables are supported; see [Hotdata SQL](https://www.hotdata.dev/docs/sql) for server behavior.
67
+
```python
68
+
t = con.table("orders")
69
+
70
+
# Filter, select, aggregate — all run as SQL on Hotdata
71
+
summary = (
72
+
t.filter(t.status =="shipped")
73
+
.group_by("region")
74
+
.agg(total=t.amount.sum(), n=t.count())
75
+
.order_by("total", ascending=False)
76
+
.execute()
77
+
)
78
+
```
60
79
61
-
## Ibis Support Overview
80
+
`.execute()` returns a **pandas DataFrame**. Use `.to_pyarrow()` for an Arrow table or `.to_pyarrow_batches()` for a record batch reader.
62
81
63
-
`hotdata-ibis` is a read-oriented SQL backend. It is useful for exploring Hotdata workspaces with Ibis expressions, running federated SQL, and materializing results locally, but it is not a full mutable database backend.
82
+
### Raw SQL
64
83
65
-
Supported today:
84
+
When you need Hotdata-specific syntax, federated table names, or SQL that Ibis doesn't model:
66
85
67
-
-**Connection setup:**`ibis.hotdata.connect(...)` and `ibis.connect("hotdata://...")` with token, workspace, optional sandbox session, TLS, timeout, and polling settings.
68
-
-**Catalog discovery:**`list_catalogs`, `list_databases`, `list_tables`, `current_catalog`, and `current_database` map Hotdata connections and remote schemas into Ibis' catalog/database/table hierarchy.
69
-
-**Table schemas:**`con.table(...)` uses Hotdata information schema column metadata and maps SQL types through Ibis' Postgres type parser.
70
-
-**SQL-backed expressions:** Ibis expressions compile with the Postgres SQLGlot compiler and execute through Hotdata. Common `SELECT` workloads such as projection, filtering, joins, grouping, aggregation, ordering, limits, scalar expressions, and `con.sql(...)` work when the generated SQL is accepted by Hotdata.
71
-
-**Result materialization:**`.execute()` returns pandas objects. `.to_pyarrow()` and `.to_pyarrow_batches()` use the Arrow IPC result data exposed by Hotdata without converting through JSON rows; batches are split locally after the result is downloaded.
72
-
-**Raw SQL escape hatch:**`con.sql("SELECT ...", dialect="postgres")` is the most reliable way to use Hotdata-specific federated table names or SQL that Ibis does not model directly.
73
-
-**Managed database lifecycle:**`create_database("sales", schema="public", tables=["orders"])` provisions a managed connection (Ibis catalog). `create_table("orders", pandas_df, database=("sales", "public"))` uploads Parquet and loads it. Query using `database=("default", "public")` or the `"default"."public"."orders"` SQL prefix. `drop_table` clears a managed table; `drop_database` deletes the connection. See [Managed databases](#managed-databases) for a complete example.
74
-
-**Parquet uploads:**`create_table` accepts pandas DataFrames, PyArrow tables, or schema-only empty tables. Tables must live in a managed connection — declare them with `create_database(..., tables=[...])`first. Loads are asynchronous; poll `_managed_table_synced(conn_id, schema, table)` if you need to query immediately. Loads always use replace mode; pass `overwrite=True` to replace an existing synced table (the default `overwrite=False` raises if the table already exists).
86
+
```python
87
+
df = con.sql(
88
+
"SELECT region, SUM(amount) AS total FROM my_conn.public.orders GROUP BY region",
89
+
dialect="postgres",
90
+
).execute()
91
+
```
92
+
93
+
You can chain Ibis expressions on the result of `con.sql(...)`the same way you would on `con.table(...)`.
75
94
76
-
Not supported as full Ibis backend features:
95
+
### Discover what's available
77
96
78
-
-**General DDL and mutations:** Arbitrary remote DDL, inserts, updates, deletes, and schema-altering operations on external connections are not implemented. Managed-database writes are limited to `create_database`, `create_table`, `drop_table`, and `drop_database` as described above.
79
-
-**Temporary tables and in-memory registration:**`supports_temporary_tables` is false, and in-memory tables are not uploaded automatically for joins.
80
-
-**Python UDFs:**`supports_python_udfs` is false.
81
-
-**Transactions and sessions as database state:** Hotdata sandbox sessions can be passed as `session_id`, but the backend does not expose transaction APIs.
82
-
-**Backend-native SQL dialect:** Compilation uses Ibis' Postgres dialect as the closest fit. Hotdata SQL and federation rules are authoritative, so not every Ibis expression that compiles is guaranteed to execute remotely.
83
-
-**Complete Ibis compliance:** The backend is experimental and has focused test coverage for connection, discovery, schema mapping, execution, uploads, and Arrow results. It has not yet been validated against the full Ibis backend test suite.
84
-
-**Hotdata platform APIs beyond SQL and managed databases:** embeddings, indexes, query history management, sandbox lifecycle management, and other Hotdata-specific APIs are outside the Ibis backend surface.
97
+
```python
98
+
con.list_catalogs() # Hotdata connection ids
99
+
con.list_databases(catalog="my_connection") # schemas for a connection
Managed databases are temporary, workspace-owned connections for uploading and querying your own data. Tables must be declared at creation time, loads are asynchronous, and SQL uses `"default"` as the catalog (not the raw connection id).
106
+
Managed databases let you upload your own data (pandas DataFrames or PyArrow tables) and query it alongside your other Hotdata connections. They are provisioned on demand and scoped to your workspace.
89
107
90
108
```python
91
109
import time
@@ -98,63 +116,69 @@ con = ibis.hotdata.connect(
98
116
workspace_id="ws_…",
99
117
)
100
118
101
-
# 1. Create the managed database and declare tables upfront.
102
-
#Tables must be declared here — load_managed_table rejects undeclared names.
119
+
# 1. Create the database and declare which tables you'll upload.
120
+
#Table names must be declared here — uploads to undeclared names are rejected.
-`create_database(..., tables=[...])` — table names must be listed here before uploading.
133
-
-`create_table(..., database=(db_id, schema))` — pass the managed database id (from `_resolve_managed_connection`) as the first element of the tuple, not the connection id.
134
-
- SQL catalog is `"default"`, not the connection id — `"default"."schema"."table"` is the correct form.
135
-
- After `create_table`, ibis table references automatically use `database=("default", schema)`; use the same form for subsequent `con.table(...)` calls.
136
-
- Loads are asynchronous. Poll `_managed_table_synced(conn_id, schema, table)` or add a small sleep before querying.
143
+
**Things to know:**
144
+
- Declare all table names in `create_database(..., tables=[...])` before uploading — you can't add them later without recreating the database.
145
+
- Use `database=("my-dataset", schema)` when uploading (`create_table`) or dropping tables (`drop_table`).
146
+
- Use `database=("default", schema)` when querying — managed tables always use `"default"` as the SQL catalog prefix.
147
+
-`create_table` accepts pandas DataFrames, PyArrow tables, or an Ibis schema for creating an empty table.
148
+
- Uploads use replace mode. Pass `overwrite=True` to replace a table that already exists; without it, uploading to an existing table raises an error.
SQL compilation uses Ibis's Postgres dialect as the closest fit. Most common `SELECT` workloads run fine; complex expressions may generate SQL that Hotdata doesn't support — use `con.sql(...)` as a fallback.
137
166
138
167
## Development
139
168
140
169
```bash
141
-
uv sync # installs dev group by default (pytest, ruff, httpx for examples)
170
+
uv sync # installs dev group (pytest, ruff, httpx)
142
171
uv run pytest
143
-
uv run ruff check src tests examples
172
+
uv run ruff check src tests
144
173
```
145
174
146
-
Lockfile CI: `uv sync --locked && uv run pytest`.
147
-
148
-
## TPC-H for the examples
149
-
150
-
Examples assume something like **`tpch.tpch_sf1.customer`**. Provision TPC-H in your workspace (commonly a **DuckDB** connection, then DuckDB’s `tpch` extension and `CALL dbgen(sf = 1)` — see [DuckDB TPC-H](https://www.duckdb.org/docs/current/core_extensions/tpch.html) and [Hotdata Quick Start](https://www.hotdata.dev/docs/quick-start)). If your data lives under `main` instead, pass `--default-schema` / `--default-connection` or set `HOTDATA_DEFAULT_*` (see `examples/_helpers.py`).
175
+
CI: `uv sync --locked && uv run pytest`.
151
176
152
177
## Examples
153
178
154
-
Needs `HOTDATA_API_KEY` and `HOTDATA_WORKSPACE`.
179
+
Set your credentials, then run any example script:
155
180
156
181
```bash
157
-
uv sync
158
182
export HOTDATA_API_KEY=…
159
183
export HOTDATA_WORKSPACE=…
160
184
uv run python examples/01_catalog_introspection.py
@@ -163,41 +187,10 @@ uv run python examples/03_connect_via_url.py
163
187
uv run python examples/04_ibis_table_workflows.py
164
188
```
165
189
166
-
### Ibis tables → pandas DataFrames
167
-
168
-
Calling **`.execute()`** on a table expression runs the compiled SQL on Hotdata and returns a **pandas**`DataFrame` (Ibis’s default for this backend).
169
-
170
-
Hotdata’s SQL often uses a **federated prefix** (for example `tpch.tpch_sf1`) that may not match the Ibis **catalog** string (the connection id). A reliable pattern is to start from **`con.sql("SELECT * FROM tpch.tpch_sf1.mytable", dialect="postgres")`**, then chain filters and aggregates—see **`examples/04_ibis_table_workflows.py`**.
171
-
172
-
When **`con.table("mytable")`** is enough (single connection/schema and names align with compiled SQL), the same operations apply:
173
-
174
-
```python
175
-
t = con.table("customer") # or con.table("customer", database=(conn_id, "tpch_sf1"))
Other useful paths: **`.to_pyarrow()`** / **`.to_pyarrow_batches()`** for Arrow; **`con.sql("SELECT …", dialect="postgres")`** then chain the returned table expression.
190
+
The examples assume a TPC-H dataset at `tpch.tpch_sf1`. To provision it: create a DuckDB connection in Hotdata, then run `CALL dbgen(sf = 1)` using DuckDB's [tpch extension](https://duckdb.org/docs/extensions/tpch.html).
0 commit comments