Skip to content

Open console query results in Positron's Data Explorer - #595

Open
samclark2015 wants to merge 1 commit into
mainfrom
sclark/ggsql-data-explorer
Open

samclark2015 wants to merge 1 commit into
mainfrom
sclark/ggsql-data-explorer

Conversation

@samclark2015

@samclark2015 samclark2015 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Addresses posit-dev/positron#16137 ("ggsql: View result of SQL query in data explorer"). No Positron changes are needed.

What it does

  • "Open in Data Explorer" link under console results. In a Positron console, a tabular result is followed by an OSC 8 hyperlink to x-ggsql-view:<session>/<key>. Positron offers clicked links to the console session's openResource, which the extension adds by wrapping the session (ggsql-vscode/src/resultLinks.ts), the same way R handles x-r-help: links. The extension then runs -- @view-result <key> silently, and the kernel opens a positron.dataExplorer comm, which Positron shows as a tab.
  • Results are kept in a private in-memory DuckDB (ggsql-jupyter/src/results.rs). The explorer therefore always uses one SQL dialect, a remote query isn't re-run for every page, and nothing appears in the user's database. The number kept is capped by --max-results (default 16), but a result with an explorer open is never evicted.
  • Explorer features: row filters (an invalid filter is flagged without breaking the others), sorting, column search, export (CSV/TSV/HTML), profiles, and Convert to Code. Convert to Code wraps the original query as a subquery, written for the session's database.
  • Clicking the link again focuses the open tab instead of opening a second explorer. The kernel sends open_editor on the UI comm with the explorer's editor URI, which is what the Variables pane does for a variable that's already open.
  • -- @view[: title] directive: opens a query's result in the Data Explorer as soon as it runs, and still shows the table in the console. A silent execution opens only the tab, so a script can trigger it. Outside Positron it shows the table with a note. VISUALISE queries are rejected.
  • Shorter console tables: like R's tibble, a result of up to 20 rows shows in full and a longer one shows its first 10, so the link stays in view. The number is set by the ggsql.consoleRows setting. The extension passes it to the kernel as the GGSQL_CONSOLE_ROWS environment variable rather than as --console-rows, because an older kernel found on the machine would refuse to start on an unknown flag. Notebooks still show up to 100 rows.

Not in this PR

  • Notebooks still get the static HTML table, not Positron's inline data grid.
  • The explorer ignores format_options, Positron's number-formatting settings.
  • Convert to Code output for a multi-statement cell won't run as it stands.

Testing

  • cargo test -p ggsql-jupyter: 104 unit tests pass.
  • ggsql-jupyter/tests: 43 integration tests pass. They cover the link, -- @view and -- @view-result, focusing an open explorer, filter/sort/Convert to Code over the comm, JSON-RPC errors, and the GGSQL_CONSOLE_ROWS row count.
  • ggsql-vscode: 78 extension tests pass, including link parsing and the consoleRows setting.
  • Checked by hand in a Positron dev build:
    • the link opens a tab, and a second click focuses it;
    • sorting, a "between" filter, and Convert to Code, where the copied SQL reproduces the filtered rows;
    • -- @view: title;
    • the 10-row cap on a 5,000-row result, and ggsql.consoleRows = 3.

Demo

ggsql-data-explorer.mp4

🤖 Generated with Claude Code

A tabular result in a Positron console is followed by an "Open in Data
Explorer" link (an OSC 8 hyperlink to x-ggsql-view:<session>/<key>). The
extension's session wrapper handles the link through openResource and runs
`-- @view-result <key>` silently; the kernel opens a positron.dataExplorer
comm on a copy of the result kept in a private in-memory DuckDB. No change to
Positron is needed. A second click focuses the open explorer through the UI
comm's open_editor event instead of opening another.

The explorer supports row filters, sorting, schema search, export and Convert
to Code, all as SQL against the retained result. Results are bounded by
--max-results; one an explorer has open is never evicted.

A `-- @view[: title]` directive opens a query's result in the Data Explorer
as soon as it runs, while still showing the table inline; outside Positron it
falls back to the table with a note.

Long console results show their first 10 rows (all of them up to 20), as R's
tibble does, so the link stays in view. The count is configurable with the
ggsql.consoleRows setting, passed to the kernel as GGSQL_CONSOLE_ROWS so
older kernels still start.

Refs posit-dev/positron#16137

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant