SQLDesk

Notebooks Beta

A chain of cells, where everything else in SQLDesk ends in one SELECT. Pull this, join it to that, reshape it, look — with the data source permissions, the result store and the scheduler you already have.

Beta, and what that means. Notebooks are shipped and supported, and they are still settling. Use them: nothing here will lose your work, because a notebook is rows in the database like a query or a dashboard, and the handoff between cells is a file that re-running rebuilds. What may change between releases is the shape of the page and what a cell is allowed to do. The badge comes off when that stops being true.

What a notebook is for

The work a saved query cannot hold. A query answers a question that fits in one statement. A great deal of real analysis does not: it is three queries against two warehouses, a join that neither of them can do, a reshape that is easier in pandas than in SQL, and a chart at the end of it.

People do that work in Jupyter today, and when they do, the warehouse never hears about it. The lineage, the permissions and the scheduling all stop at the edge of somebody’s laptop — and so does the answer, which arrives in Slack as a screenshot nobody can re-run. A notebook keeps that work where the rest of your data lives: same data sources, same permissions, same workers, same audit log.

A notebook is a draft until you publish it, the same promise queries and dashboards make. What you are still building is not in anybody else’s list.

When to reach for one instead of a query

Reach for a query when the answer is one statement and the point is to re-run it; reach for a dashboard when the point is to watch numbers change.

Cells

Cells are named, never numbered. A later cell refers to this one by name — as a relation in SQL, as a dataframe in Python — so inserting, deleting and reordering leave every reference pointing at what it meant. A name is letters, digits and underscores, not starting with a digit, because it has to be legal as a table name and as a variable at the same time.

A text cell is Markdown for the reader, between the steps. It has no name, because nothing reads it; it never runs, and Run all goes past it. Upgrading to the release that brought text cells turned each cell’s title into a ### Title text cell directly above it.

The name, the title, and how you find them

Each cell has a title, which is for reading, and a name, which is what later cells type. Both are on the cell: the title in plain text, the name beside it in monospace. Click the name and it is copied, because the next thing you do with it is paste it into the cell below.

You rarely set both. Titling a cell Orders, cleaned names it orders_cleaned — as long as the name is still the generated one and no other cell refers to it yet. Once something reads a cell, its name is pinned: references live in other cells’ SQL, and quietly rewriting somebody’s query is worse than an unhelpful name. Rename it yourself from the cell’s “…” menu, and every handoff follows.

Two more places answer the same question, so you never have to remember a name:

Only what is really readable appears: a name is offered because a cell above handed over a table, so a cell that printed text is correctly absent and you never write a reference that cannot resolve. A cell is only ever offered the cells above it; a notebook runs down the page.

A SQL cell

A SQL cell is one of two things, and which one it is follows from whether you give it a data source:

It cannot be both, and the cell says so before you run it. A warehouse has never heard of a cell called orders, and SQLDesk is not going to push four million rows into it to pretend otherwise.

SQL over earlier cells is DuckDB, so it is DuckDB’s dialect — which is close enough to Postgres that most things work, and better than most at the things this is for: QUALIFY, GROUP BY ALL, EXCLUDE, struct and list columns, and joins across relations that came from different warehouses.

A Python cell

A Python cell computes; it cannot query. It reads an earlier cell’s output as a pandas dataframe under that cell’s own name, and nothing else. That is the strongest rule in the design, for what it removes: no credential ever reaches the interpreter, because there is nothing for it to reach. Anything that needs the warehouse needs a SQL cell above it.

Variables persist between cells, as they do in Jupyter: df assigned in one cell is still there five cells later. If the last line of a cell is an expression, its value is the cell’s output — a dataframe becomes a relation later cells can read, and anything else is text to look at.

print() is kept too, and shown under the cell. A cell that printed has no relation for the next cell to read, and the page says which it produced rather than leaving you to find out by writing a reference that fails.

Python cells need an interpreter, which is off by default. Without one, the cell says so rather than failing when somebody runs it.

A Scala cell

A Scala cell runs against your Spark cluster, never in SQLDesk, which has no JVM in it. spark is a session on the cluster, and org.apache.spark.sql.functions._ and spark.implicits._ are already imported. Unlike a Python cell it may read the cluster’s own tables (spark.table("sales")), so it needs no cell above it.

Scala runs on Spark Connect only, Spark 4 and later, and only in a notebook whose compute is a Spark Connect cluster. An administrator runs the notebook executor from the Scala image, built at the clusters’ Spark version: docker build -f Dockerfile.executor-scala --build-arg SPARK_VERSION=4.0.1 ., and sets notebooks.image to it. Each notebook then gets a Scala interpreter in the executor, holding a Connect session on its cluster. The Scala compiles there, and the cluster receives the plans its DataFrames make, plus the classes of any lambda or udf. A session starts in a few seconds. Each one is a JVM of notebooks.spark.scala.heap (512 MB) and counts against notebooks.maxSessions, so size the executor’s memory limit to match. A cell busy in plain Scala rather than in Spark does not hear a stop, and its interpreter is ended after 15 seconds.

On Local Python, or where the executor has no Scala, the Scala option is still offered and says what it needs. (Livy is not supported: a cluster without a Connect server cannot run Scala cells.)

Charts a cell draws itself

End a Python cell on a figure and it is drawn. matplotlib, seaborn and df.plot() come back as images; plotly comes back interactive, so you can hover and zoom in the notebook and in anything you share from it.

import plotly.express as px
px.bar(by_city, x="city", y="total", title="Takings by city")

That is separate from a chart on a cell, below, which is SQLDesk’s own chart editor over the cell’s table. Use the editor when you want the chart types and the controls the rest of SQLDesk has; write the figure yourself when you want something SQLDesk does not offer.

Stale, and why nothing is corrected for you

A notebook with a session is a notebook that can rot: the number in cell four was computed from cell one, cell one has been edited and re-run twice since, and nothing on the page says so. That is the normal failure of every notebook tool with hidden state.

So every run records which cells it read, and a cell whose inputs have re-run since is marked stale — and left exactly as it was. The number on the screen is still the number that was computed; re-running it is your decision. Staleness carries: if A feeds B and B feeds C, re-running A marks both.

A cell whose input was deleted says something different, because it is a different problem: that one cannot be reproduced at all, where a stale one only needs re-running.

What is kept, and what is thrown away

Three things, with three different lifetimes:

The table under a cell shows the slice and says what it is a slice of: first 1,000 of 4,200,000 rows. The next cell reads the whole thing, not what you can see.

Download on a cell gives you the whole relation as CSV — the handoff, not the slice. A download that quietly handed over a thousand rows of four million would be wrong in the way that is hardest to notice, because it would look right.

Archiving a notebook keeps all of it except the handoff, which re-running rebuilds.

Reading a long one

A notebook of thirty cells is a document, and the page treats it as one.

A chart on a cell

Any cell that produced a table can carry a visualization, with the same editor and the same chart types as a query. It is drawn from the rows on the page rather than the whole handoff — a chart of four million points is a smear.

A cell’s chart cannot yet become a dashboard widget. Refreshing a widget backed by cell seven means running cells one to seven, on an interpreter, on a dashboard’s refresh interval — that is a scheduling design rather than a widget, and it is not in this release.

Running and stopping

A cell runs on a worker, like a query, and a SQL cell takes a query slot from its data source’s pool like any other query — the warehouse’s connection limit does not get larger because something was typed into a notebook.

Run all runs the chain in order, as one job on a worker rather than a loop in your browser — so closing the tab does not stop it halfway and leave a notebook that looks like it ran. It stops at the first cell that fails, because everything below would be reading what that cell did not produce.

Stop cancels the cell that is running and does not start the next. It does not throw the notebook away: the variables earlier cells assigned are still there afterwards. A cell that ignores the interruption entirely is ended after a few seconds, and the page says that is what happened.

A Scala cell’s work is on the cluster, so stop cancels it there, and the cell says “Stopped: the cell was cancelled on the cluster”. Its session and values stay. A Scala cell busy in plain Scala rather than in Spark cannot hear a stop, so its interpreter is ended after 15 seconds. The next Scala cell then starts a fresh session and sends the earlier cells’ rows again.

Running it on a schedule

A published notebook can run itself on a cron expression — every morning before the standup, every weekday at seven, the first of the month. There are presets for the common ones and a box for the rest.

Cron rather than a query’s interval, because it answers a different question. A query’s schedule means keep this no more than an hour stale; a notebook’s means have this done by the time I look. The expression is checked when you save it: one that does not parse would otherwise quietly mean “never”, which is the worst answer a schedule can give.

A scheduled run is the same as Run all: it runs as you, with your data source access, and stops at the first failure. Drafts do not run — what you are still building should not start running itself overnight.

Sharing one

Everything that hands a notebook to somebody else is behind the Share button, in the same shape a dashboard’s is.

What is captured is the cells, not the page around them — and folded cells stay folded, because a notebook somebody tidied is the report they meant to send.

Turning Python and Scala cells on

Python runs in a container of its own — never in the worker, which is the process holding every data source’s decrypted credentials. It is built and run only by installs that want it:

docker compose --profile notebooks up executor

Then point SQLDesk at it with SQLDESK_NOTEBOOK_EXECUTOR_URL and give both sides the same SQLDESK_NOTEBOOK_EXECUTOR_TOKEN. Deny that container egress and give it a memory limit: the design makes the first free, since a code cell has nothing it needs to reach, and the second is the real ceiling on what one cell can spend.

For Scala cells as well, run the interpreter from the Scala image instead. It is the same service, Python cells included, with a JDK and Spark’s jars added (about 700 MB more):

docker build -f Dockerfile.executor-scala \
  --build-arg SPARK_VERSION=4.0.1 -t sqldesk-executor:scala .

Build it at your clusters’ Spark version. Which cluster a notebook runs on is the notebook’s compute, not a setting of the executor. The rest is in A Scala cell. The executor images are not published, so build whichever one you run.

In the Scala imageWhat it does
EXECUTOR_SCALA_HEAPEach notebook’s JVM heap, 512m by default; the chart sets it from notebooks.spark.scala.heap. Size the container’s memory for EXECUTOR_MAX_SESSIONS of them, plus the Python sessions.
EXECUTOR_SCALA_START_SECONDSHow long a session may take to start, 120 by default. One starts in about five seconds against a reachable server.
EXECUTOR_SCALA_STOP_GRACE_SECONDSHow long stop waits for a cell to notice before ending its interpreter, 15 by default.

Who may use notebooks at all is a permission an administrator grants per group, under Groups, like the other features.

Where a notebook’s code runs

Each notebook chooses its compute at the top of the page: Local Python, the executor’s own container, or a Spark cluster. A cluster is a Spark Connect data source, added by an administrator under Settings → Data Sources with its sc:// address, token, TLS and Spark settings. It is never queried like a warehouse — a SQL cell cannot pick it — and its groups decide who may run code on it: full access, not view only. Everybody sees every cluster in the list; one your groups cannot use says who can help. Switching compute stops the notebook’s session.

Python on a Spark cluster

Build the interpreter with a Spark Connect client:

docker compose build \
  --build-arg WITH_SPARK=true \
  --build-arg SPARK_VERSION=3.5.3 executor

The version has to match the cluster: Spark Connect’s client and server are versioned together, and a mismatch shows up as a protocol error on the first call rather than at build time.

In a notebook whose compute is a cluster, Python cells have spark, a session on that cluster opened when the notebook’s session starts — so a wrong address or token fails there, where the page can say so, rather than on somebody’s first cell. Two notebooks can be on two clusters at once.

A Spark DataFrame returned by a cell is collected to become that cell’s handoff, which is the one moment the cluster’s answer has to fit in one container. It is bounded, and a result over the bound is refused with a sentence rather than quietly cut down — a notebook that showed you the first million rows of a billion without saying so would be worse than one that said no. Aggregate in Spark before returning.

Note what changes when Spark is configured: the interpreter now needs a route to the cluster, so “no egress” becomes “egress to the cluster only” — and that is only as true as whatever enforces it. In Kubernetes, a NetworkPolicy whose single egress rule is the Spark service says it exactly.

What a notebook will not do