diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml new file mode 100644 index 0000000..c2b9d31 --- /dev/null +++ b/.github/workflows/pages.yml @@ -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 diff --git a/.gitignore b/.gitignore index 55dc4f8..93272bc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build/ .mypy_cache/ .ruff_cache/ _site/ +node_modules/ diff --git a/README.md b/README.md index ed044ce..7755eda 100644 --- a/README.md +++ b/README.md @@ -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 `*` @@ -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]" @@ -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 diff --git a/docs/demo.gif b/docs/demo.gif new file mode 100644 index 0000000..e1654c5 Binary files /dev/null and b/docs/demo.gif differ diff --git a/site/smoke.mjs b/site/smoke.mjs new file mode 100644 index 0000000..88911a6 --- /dev/null +++ b/site/smoke.mjs @@ -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`);