Commit 3e688b3
authored
feat: support HTTP DuckDB queries in WASM notebooks (#9480)
Motivated by marimo-team/quarto-marimo#74,
marimo-team/jupyter-book-marimo#1, and #9413.
DuckDB remote file queries fail in Pyodide because DuckDB-WASM [can't
use httpfs](https://duckdb.org/2024/10/02/pyodide#limitations).
Therefore, URL-based SQL like `FROM
'https://...'` and `read_csv/read_parquet/read_json('https://...')` are
unusable in WASM notebooks today.
This PR adds a DuckDB WASM fallback layer for `mo.sql`, SQL cells, raw
`duckdb.sql/query/execute/query_df`, connection SQL methods, and direct
`duckdb.read_csv/read_parquet/read_json` calls.
It translates queries such as
```sql
SELECT * FROM read_csv('https://example.com/cars.csv')
SELECT * FROM 'https://example.com/cars.csv'
-- or duckdb.read_csv('https://example.com/cars.csv') via Python API
```
into
```sql
SELECT * FROM __marimo_wasm_duckdb_remote_0
```
where `__marimo_wasm_duckdb_remote_0` is bound to a fetched pandas
DataFrame, which DuckDB can query through Python replacement scans.
Underneath, the fallback layer:
- uses sqlglot to analyze SQL and extract supported static remote file
references from the AST
- fetches remote files through Python/urllib via marimo's shared WASM
fetch util
- decodes fetched DuckDB file bytes into pandas DataFrames
- hands those DataFrames back to DuckDB under generated table names
Unsupported or dynamic cases are left to DuckDB's normal path. The patch
is a no-op outside Pyodide, and in Pyodide the DuckDB SQL fallback
requires `sqlglot` for AST analysis.
Tested with unit coverage for the rewrite/fetch/read paths and manually
in the WASM playground against hosted CSV, parquet, JSON, and GeoJSON
datasets.
## WASM Playground Demo
Demonstrates that the Pyodide-build of marimo supports querying remote
files with DuckDB across cases like:
- CSV via `mo.sql`: direct URL scan
- Parquet via `duckdb.sql`: `read_parquet(...)`
- Direct `duckdb.read_csv` Python API with patched options (custom
delimiter)
- JSON / GeoJSON path
- Connection API via `duckdb.connect`
https://github.com/user-attachments/assets/a2b310ed-2677-4f67-81da-3d8ea21452541 parent 47fc5a1 commit 3e688b3
17 files changed
Lines changed: 3526 additions & 52 deletions
File tree
- frontend/src/core
- islands/worker
- wasm
- __tests__
- worker
- marimo
- _output/formatters
- _runtime/_wasm
- _duckdb
- _sql
- tests/_runtime
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
89 | | - | |
| 89 | + | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
163 | 164 | | |
164 | 165 | | |
165 | 166 | | |
166 | | - | |
167 | | - | |
| 167 | + | |
| 168 | + | |
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
141 | 142 | | |
142 | 143 | | |
143 | 144 | | |
144 | | - | |
145 | | - | |
| 145 | + | |
| 146 | + | |
146 | 147 | | |
147 | 148 | | |
148 | 149 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
163 | 175 | | |
164 | 176 | | |
165 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
| 58 | + | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| |||
0 commit comments