Skip to content

feat(config): configurable SQL keyword case for generated SQL - #10657

Draft
sha2fiddy wants to merge 3 commits into
marimo-team:mainfrom
sha2fiddy:feat/sql-keyword-case
Draft

feat(config): configurable SQL keyword case for generated SQL#10657
sha2fiddy wants to merge 3 commits into
marimo-team:mainfrom
sha2fiddy:feat/sql-keyword-case

Conversation

@sha2fiddy

Copy link
Copy Markdown
Contributor

This pull request was authored by a coding agent.

📝 Summary

Closes #10656

Adds a runtime.sql_keyword_case config key ("upper" or "lower", default "upper") that controls the keyword case of SQL that marimo generates:

  • new SQL cell boilerplate (SELECT * FROM / select * from )
  • SQL keyword autocompletions
  • table/column snippets in the Data Sources panel (all dialect formatters)
  • the AI datasource tool's sample_query

The default preserves today's behavior exactly. A drift-guard test pins the adapter's default boilerplate to SQLParser.defaultCode under the default config.

Related: #10115, where the feedback was that keyword case should be configurable without overfitting to sql-formatter.

Scope / non-goals

  • Format-SQL is untouched. Formatting a cell today preserves the case of hand-written SQL, and mapping this key to sql-formatter's keywordCase would start rewriting user SQL on format. If wanted, that seems better as a separate formatting-scoped key in a follow-up.
  • AI prompt templates are untouched.
  • I placed the key under runtime next to default_sql_output; happy to move it to another section if you prefer.

Implementation notes

  • sql_keyword_case is NotRequired in the Python TypedDict (the OpenAPI required list is unchanged), present in DEFAULT_CONFIG, and zod-prefaulted, the same shape as show_tracebacks.
  • New helper 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).
  • The keyword completion source reads the config per-request inside the closure, so changing the setting applies without a reload.
  • Settings UI: a "SQL keyword case" select in the SQL group of the editor settings, after "Default SQL output".
  • packages/openapi/api.yaml + src/api.ts regenerated via make fe-codegen; tests/_server/templates/snapshots/* regenerated via make py-snapshots.
  • Docs: a short "SQL keyword case" blurb under Utilities in the SQL guide. marimo config describe picks up the docstring.

Tests: new keyword-case.test.ts; lowercase variants in sql.test.ts (defaultCode, completions, drift guard); a lowercase describe in datasources/__tests__/utils.test.ts covering each formatter branch including quoted-identifier preservation; config snapshot updates; test_datasource_tool.py unit and end-to-end lowercase cases.

📋 Pre-Review Checklist

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes.
  • Tests have been added for the changes made.

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.
@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview Aug 25, 2026 4:44pm

Request Review

@github-actions github-actions Bot added documentation Improvements or additions to documentation bash-focus Area to focus on during release bug bash labels Aug 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make generated SQL keyword case configurable (autocomplete, new-cell boilerplate, datasource snippets)

2 participants