feat(config): configurable SQL keyword case for generated SQL - #10657
Draft
sha2fiddy wants to merge 3 commits into
Draft
feat(config): configurable SQL keyword case for generated SQL#10657sha2fiddy wants to merge 3 commits into
sha2fiddy wants to merge 3 commits into
Conversation
Adds an "upper" | "lower" setting (default "upper", today's behavior) controlling the keyword case of SQL that marimo generates. Includes the zod schema, settings UI select, regenerated OpenAPI spec/client, and regenerated export snapshots.
New sqlKeyword()/sqlKeywordCase() helper reads the resolved config lazily so setting changes apply without a reload. Applied to keyword autocompletions, SQL cell defaultCode (both engine variants), and all Data Sources panel snippet formatters; identifiers are never re-cased. A drift guard pins defaultCode to SQLParser.defaultCode under the default config.
Reads the session config once per _get_tables call and threads a keyword_case argument into _form_sample_query. Adds a docs blurb under the SQL guide's Utilities section.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new runtime configuration key to control whether generated SQL keywords are emitted in uppercase or lowercase, threading that setting through the editor’s SQL boilerplate, keyword autocomplete, datasource snippets, and the AI datasource tool, while preserving the current uppercase default.
Changes:
- Introduces
runtime.sql_keyword_case: "upper" | "lower"(default"upper") in Python config, frontend zod schema, and OpenAPI output. - Applies the configured keyword casing to SQL cell boilerplate, SQL keyword completions, datasource panel snippets, and AI datasource
sample_query. - Adds targeted frontend and Python tests + updates snapshots and documentation.
Reviewed changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/_server/templates/snapshots/export1.txt | Updates snapshot config payload to include runtime.sql_keyword_case. |
| tests/_server/templates/snapshots/export2.txt | Updates snapshot config payload to include runtime.sql_keyword_case. |
| tests/_server/templates/snapshots/export3.txt | Updates snapshot config payload to include runtime.sql_keyword_case. |
| tests/_server/templates/snapshots/export4.txt | Updates snapshot config payload to include runtime.sql_keyword_case. |
| tests/_server/templates/snapshots/export5.txt | Updates snapshot config payload to include runtime.sql_keyword_case. |
| tests/_server/templates/snapshots/export6.txt | Updates snapshot config payload to include runtime.sql_keyword_case. |
| tests/_ai/tools/tools/test_datasource_tool.py | Adds unit + integration-style tests ensuring lowercase keyword case is respected in generated sample_query. |
| tests/_ai/tools/test_utils.py | Adds a MockConfigManager and wires it into AI tool test sessions. |
| packages/openapi/src/api.ts | Regenerates TS OpenAPI types to include runtime.sql_keyword_case. |
| packages/openapi/api.yaml | Regenerates OpenAPI schema to include runtime.sql_keyword_case. |
| marimo/_config/config.py | Adds SqlKeywordCase type, documents the new key, and sets default in DEFAULT_CONFIG. |
| marimo/_ai/_tools/tools/datasource.py | Threads config-driven keyword casing into AI datasource tool sample_query generation. |
| frontend/src/core/config/config-schema.ts | Adds frontend schema/type for sql_keyword_case with default "upper". |
| frontend/src/core/config/tests/config-schema.test.ts | Updates frontend config schema tests to assert the new default key is present. |
| frontend/src/core/codemirror/language/languages/sql/keyword-case.ts | Introduces helper to read config and case keyword fragments consistently. |
| frontend/src/core/codemirror/language/languages/sql/sql.ts | Updates SQL adapter default boilerplate to use configurable keyword casing. |
| frontend/src/core/codemirror/language/languages/sql/completion-sources.tsx | Makes keyword completion casing driven by current config per request. |
| frontend/src/core/codemirror/language/languages/sql/tests/keyword-case.test.ts | Adds unit tests for keyword casing helper behavior. |
| frontend/src/core/codemirror/language/tests/sql.test.ts | Adds drift-guard + lowercase coverage for boilerplate and keyword completions. |
| frontend/src/components/datasources/utils.ts | Updates datasource panel SQL snippets to use configurable keyword casing (all formatter branches). |
| frontend/src/components/datasources/tests/utils.test.ts | Adds lowercase keyword-case tests (including quoted identifier preservation). |
| frontend/src/components/app-config/common.tsx | Adds select options for the new UI setting. |
| frontend/src/components/app-config/data-form.tsx | Adds “SQL keyword case” select to editor settings UI under the SQL group. |
| docs/guides/working_with_data/sql.md | Documents the new sql_keyword_case setting and clarifies it affects only generated SQL. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+36
to
+37
| def get_config(self) -> Any: | ||
| return self.config if self.config is not None else DEFAULT_CONFIG |
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.
This pull request was authored by a coding agent.
📝 Summary
Closes #10656
Adds a
runtime.sql_keyword_caseconfig key ("upper"or"lower", default"upper") that controls the keyword case of SQL that marimo generates:SELECT * FROM/select * from)sample_queryThe default preserves today's behavior exactly. A drift-guard test pins the adapter's default boilerplate to
SQLParser.defaultCodeunder the default config.Related: #10115, where the feedback was that keyword case should be configurable without overfitting to sql-formatter.
Scope / non-goals
keywordCasewould start rewriting user SQL on format. If wanted, that seems better as a separateformatting-scoped key in a follow-up.runtimenext todefault_sql_output; happy to move it to another section if you prefer.Implementation notes
sql_keyword_caseisNotRequiredin the Python TypedDict (the OpenAPIrequiredlist is unchanged), present inDEFAULT_CONFIG, and zod-prefaulted, the same shape asshow_tracebacks.frontend/.../sql/keyword-case.ts(sqlKeywordCase()/sqlKeyword(fragment)). It takes keyword fragments only, never identifiers, so quoted identifiers keep their case (covered by a postgres-family test).packages/openapi/api.yaml+src/api.tsregenerated viamake fe-codegen;tests/_server/templates/snapshots/*regenerated viamake py-snapshots.marimo config describepicks up the docstring.Tests: new
keyword-case.test.ts; lowercase variants insql.test.ts(defaultCode, completions, drift guard); a lowercase describe indatasources/__tests__/utils.test.tscovering each formatter branch including quoted-identifier preservation; config snapshot updates;test_datasource_tool.pyunit and end-to-end lowercase cases.📋 Pre-Review Checklist
✅ Merge Checklist