Run `{sql}` code cells with ggsql, as for `.sql` files

Đang mở
#619 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 6 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
jupyter-notebook, rust, sql
Lĩnh vực
tooling

Hướng nghiên cứu

Start by reproducing the example document with quarto render and confirming that the {sql} cell is dropped before the ggsql kernel sees it. Then trace Quarto's cell-language filtering and its langCommentChars handling in quarto-cli, and compare with ggsql-jupyter's kernel language registration. The design questions (opt-out location, SQL-only default, knitr behavior, both #| and --| prefixes) need maintainer decisions first; the linked Positron work and knitr DBI behavior constrain the answer. Done means {sql} cells render through ggsql under jupyter: ggsql, with a documented opt-out and both option prefixes accepted.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

positron-sql

The ggsql extension already runs plain .sql files in the ggsql console. The ggsql.enableSqlFiles setting is on by default, because ggsql is a superset of SQL. I am proposing that ggsql also take over {sql} code cells in Quarto documents, on the same terms.

Current behavior

A {sql} cell contains the same SQL as a .sql file, but ggsql does not run it when you render:

  • ggsql-jupyter reports its language as ggsql. The Jupyter engine in Quarto runs only the cells in the language of the kernel, so in a jupyter: ggsql document, {sql} cells won't render. {ggsql} cells in the same document render as usual.
  • In a document that has only {sql} cells and no jupyter key, Quarto tries to select a Python kernel, not ggsql.

Positron is working on running {sql} cells with ggsql in the editor in posit-dev/positron#17401, except in knitr documents. When that change ships, a document can run correctly cell by cell (like with inline output or in the console) but will render with no SQL output.

Reproducible example

---
title: "SQL cells with ggsql"
format: html
jupyter: ggsql
---

```{ggsql}
-- @connect: duckdb://memory
SELECT 1 AS from_ggsql_cell
```

```{sql}
SELECT 2 AS from_sql_cell
```

Render it with quarto render. The {ggsql} cell shows a table while the {sql} cell doesn't execute.

Versions: Quarto 1.11.9, ggsql-jupyter 0.5.2.

Proposal

When a document has jupyter: ggsql, run its {sql} cells in the ggsql kernel together with its {ggsql} cells. The document already opts in to ggsql with that key, so this is similar to the .sql file behavior.

Some questions:

  1. Where does the change go? Quarto filters cells by language before the kernel gets them, so a change in ggsql-jupyter alone is not sufficient. The change can go in quarto-cli, or in a Quarto integration that ggsql supplies.
  2. How does a user opt out? ggsql.enableSqlFiles is an editor setting, and quarto render cannot read it. An opt-out for render must be in the document or the project, for example in the front matter.
  3. Is it on by default for SQL-only documents too? A document with only {sql} cells and no jupyter key has no other kernel to use. ggsql is a good default for that document, but this would be a larger change.
  4. What about knitr documents? knitr runs {sql} chunks with DBI, on the R connection that each chunk names. These documents have to keep that behavior.

Related: cell option comment characters

quarto-cli has no ggsql entry in langCommentChars, so Quarto removes only #| option lines from {ggsql} cells. ggsql-jupyter does not remove option lines itself so a {ggsql} cell with --| options (the usual prefix for {sql} cells) fails to render with "Parse error: Parse tree contains errors". If {sql} cells run in ggsql, both prefixes must work in both cell types.

cc @samclark2015

Ngôn ngữ chính
Rust
Star
573
Fork
32
Merge trung bình
8 ngày 23 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của posit-dev/ggsql

Tất cả issue của posit-dev/ggsql

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.