Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: pages

# Build the in-browser demo from site/ and publish it to GitHub Pages.
on:
push:
branches: [main]
pull_request:
paths: ["site/**", "tinyquery/**", ".github/workflows/pages.yml"]
workflow_dispatch:

permissions:
contents: read

# One deploy at a time; a newer push supersedes a queued one.
concurrency:
group: pages-${{ github.ref }}
cancel-in-progress: false

jobs:
build:
name: Build and smoke-test the demo
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
cache-dependency-path: pyproject.toml

- uses: actions/setup-node@v4
with:
node-version: "22"

- name: Install with the tinydelta extra
run: python -m pip install ".[delta]"

- name: Build the site
run: python site/build.py --out _site

# pytest runs demo.py natively, where os.link exists. This loads the
# built bundle into the same Pyodide release app.js uses, so a demo that
# only breaks in the browser never gets published.
- name: Smoke-test the bundle in Pyodide
run: |
npm install --no-save pyodide@314.0.7
node site/smoke.mjs _site

- uses: actions/upload-pages-artifact@v3
with:
path: _site

deploy:
name: Deploy to GitHub Pages
if: github.event_name != 'pull_request'
needs: build
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ build/
.mypy_cache/
.ruff_cache/
_site/
node_modules/
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Single node SQL engine. You write a small subset of SQL, it parses it, builds an

This is the same shape as Spark/Postgres (parse → plan → operators), on one machine, in memory.

**[Try it in your browser](https://spookyjumpybeans.github.io/tinyquery/)**: tinyquery
and [tinydelta](https://github.com/SpookyJumpyBeans/tinydelta) running under Pyodide,
with every query's plan drawn as estimated vs actual rows.

[![The demo: a plan tree with estimated and actual row bars, a version timeline, and planner switches](docs/demo.gif)](https://spookyjumpybeans.github.io/tinyquery/)

## What works

- `SELECT` columns or `*`
Expand Down Expand Up @@ -209,15 +215,16 @@ pytest

## In the browser

`site/` is a static page that runs tinyquery and tinydelta in the browser with
[Live demo.](https://spookyjumpybeans.github.io/tinyquery/) `site/` is a static
page that runs tinyquery and tinydelta in the browser with
[Pyodide](https://pyodide.org). It builds a small shop -- a tinydelta `orders`
table with six versions, plus customers and line items -- and runs every query
under `EXPLAIN ANALYZE`. The plan is drawn as a tree, with estimated and actual
rows as paired bars on one log scale, and any operator off by 10x or more is
flagged, the same as in the text output. A timeline under the query moves every table read
to an older version of `orders`, an Append button commits a new one, and
switches turn join reordering and predicate pushdown off so you can watch the
plan change.
flagged, the same as in the text output. A timeline under the query moves
every read to an older version of `orders`, an Append button commits a new one,
and switches turn join reordering and predicate pushdown off so you can watch
the plan change.

```bash
pip install -e ".[delta]"
Expand All @@ -230,6 +237,12 @@ finished temp file to its version name. The demo stands in with exclusive
create plus copy, which is only safe because a browser tab runs one Python
thread. Run natively, the real `link()` is used.

Every push to `main` rebuilds the page and publishes it to GitHub Pages
(`.github/workflows/pages.yml`). Before publishing, `site/smoke.mjs` loads the
built bundle into the same Pyodide release the page uses and runs every preset
under every planner setting. The pytest suite runs `demo.py` natively, where
`os.link` exists, so this is the only check on the browser path.

## How a query runs

```text
Expand Down
Binary file added docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions site/smoke.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Load the built site's bundle into Pyodide under Node and drive it the way
// app.js does. The pytest suite runs demo.py natively, where os.link exists,
// so this is the only check that the browser path works: the os.link
// stand-in, the bundle layout, and the code under Pyodide's Python.
//
// Run after site/build.py, with pyodide installed at the version app.js loads:
// npm install --no-save pyodide@314.0.7
// node site/smoke.mjs _site

import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { loadPyodide } from "pyodide";

const site = process.argv[2] ?? "_site";
const pyodide = await loadPyodide();
// unpackArchive rejects a Node Buffer; the page hands it an ArrayBuffer.
const bundle = new Uint8Array(await readFile(join(site, "packages.zip")));
pyodide.unpackArchive(bundle, "zip", { extractDir: "/lib" });
pyodide.runPython("import sys; sys.path.insert(0, '/lib')");

const hasLink = pyodide.runPython("import os; hasattr(os, 'link')");
const demo = pyodide.pyimport("demo");
const failures = [];
const check = (ok, message) => {
if (!ok) failures.push(message);
};

const history = JSON.parse(demo.setup("/data"));
check(history.length === 6, `expected 6 versions, got ${history.length}`);

for (const preset of JSON.parse(demo.presets())) {
for (const [reorder, pushdown] of [[true, true], [false, true], [true, false]]) {
for (const version of [1, history.length - 1]) {
const result = JSON.parse(demo.run(preset.sql, version, reorder, pushdown));
const where = `${preset.name} at v${version}, reorder=${reorder}, pushdown=${pushdown}`;
check(!result.error, `${where}: ${result.error}`);
check(result.version === version, `${where}: read v${result.version}`);
check(result.plan?.operator, `${where}: plan has no operator`);
}
}
}

const appended = JSON.parse(demo.append_orders(200));
check(appended.length === history.length + 1, "append_orders did not add a version");
check(appended.at(-1).rows === history.at(-1).rows + 200, "append_orders added the wrong row count");

console.log(`Python ${pyodide.runPython("import sys; sys.version.split()[0]")} in Pyodide ${pyodide.version}`);
console.log(`os.link ${hasLink ? "present" : "missing, so the demo's stand-in was used"}`);
if (failures.length) {
console.error(failures.join("\n"));
process.exit(1);
}
console.log(`ok: ${appended.length} versions, every preset ran under every setting`);
Loading