Repository navigation
Conversation
…rame pages Add @deepnote/stored-dataframes, a Node.js-only package for serving one page of a dataframe that deepnote-toolkit's store_dataframe stored, as JSON: - storage layout and dataframeDirectory for named and block frames - manifest schema and parseManifest - page request and HTTP query schemas - planDataframePage and slicePageColumns - error classes with dataframePageErrorResponse (400 / 404 / 422) - describeColumns and encodeRows, the Arrow-to-JSON value encoder, with the JSON-byte and value budgets as optional hooks and event-loop yielding apache-arrow ^21.2.0 is a peer dependency, because the encoder checks instanceof against the consumer's apache-arrow classes. The package does no file I/O and registers no compression codec. Adds two Arrow fixtures under test-fixtures/stored-dataframes/: a synthetic pandas/pyarrow frame with its generator, and a frame deepnote-toolkit 2.9.1 stored.
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #669 +/- ##
==========================================
+ Coverage 91.28% 91.52% +0.23%
==========================================
Files 234 241 +7
Lines 13600 13979 +379
Branches 3876 3965 +89
==========================================
+ Hits 12415 12794 +379
Misses 1182 1182
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
encodeRows built a binary cell's base64 string and only then charged its length through chargeJsonBytes, so a cell over the caller's JSON budget allocated 4/3 of its bytes before the hook could refuse it, and a cell past V8's string limit failed with Node's ERR_STRING_TOO_LONG instead of the hook's error. encodeBinary now charges the exact JSON length, 4 * ceil(n / 3) + 2, first, as encodeDecimal does for its text. The total charged per cell is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
@deepnote/stored-dataframes, a Node.js-only package that holds the format layer for serving one page of a dataframe that deepnote-toolkit'sstore_dataframe(df, name)stored, the wayGET /v2/projects/:projectId/dataframes/:nameanswers it. Deepnote Cloud's dataframe API and the vscode-deepnote app preview (deepnote/vscode-deepnote#622) each keep their own copy of this logic today. The API is shaped so both can switch to the package without further changes here.The package exports:
dataframeDirectoryfor named (deepnote_dataframes/<name>/) and block (.deepnote/dataframes/<notebookId>/<blockId>/) frames, plus the layout constants.manifestSchemaandparseManifest, which returnsnullfor anything that isn't a valid manifest and ignores extra keys.dataframePageRequestSchema, anddataframePageQuerySchemafor HTTP queries (coerced, defaulted and strict).planDataframePage, which works out which record batches and row ranges a page covers, andslicePageColumns, which joins those ranges into one vector per column.dataframePageErrorResponse. A request error answers 400. A missing or invalid frame answers 404 withDataframe not foundand never the error's detail. A frame or page the server can't serve answers 422. The constructors are public, so a consumer can add its own reasons by subclassing.describeColumnsandencodeRows, the Arrow-to-JSON value encoder.chargeJsonBytes,chargeValues). Without them no charge is computed andJSON.stringifyis never called.encodeRowsrejects with that same instance, except that anInvalidArrowFileErrorthrown while a cell is encoded becomes anunreadable_rowerror.apache-arrow^21.2.0 is a peer dependency, because the encoder usesinstanceofchecks against the consumer's apache-arrow classes. The package does no file I/O and registers no compression codec.Also adds two fixtures under
test-fixtures/stored-dataframes/:encoding/: a synthetic pandas/pyarrow frame (30 rows, 17 column types, 3 zstd batches), with its generator script.toolkit_frame/: a frame that deepnote-toolkit 2.9.1 stored.Testing
packages/stored-dataframes:JSON.stringifywithoutchargeJsonBytes, and which errors keep their identity and which are wrapped;pnpm typecheck,pnpm biome:check,pnpm prettier:checkandpnpm --filter @deepnote/stored-dataframes buildpass. The build emits ESM and CJS and keepsapache-arrowandzodexternal.pnpm test: everything passes except 3 cases inpackages/cli/src/commands/run.test.ts. Those fail only because this machine has nopythonbinary on PATH, and they pass with one added.