Skip to content

Conversation

@Light2Dark
Copy link
Contributor

@Light2Dark Light2Dark commented Sep 24, 2025

📝 Summary

Adds a parse function in /validate endpoint that currently supports duckdb so we get better lint errors when writing SQL cells.

/validate runs SELECT JSON_SERIALIZE_SQL in duckdb, which returns a structured error response (for a majority of queries)
https://duckdb.org/docs/stable/data/json/sql_to_and_from_json.html.

We then convert the json response to linter error format

    message: str
    line: int
    column: int
    severity: Literal["error", "warning"]

A custom sql parser is created to use this new endpoint, everytime the parser runs validateSql for DuckDB, it will call this endpoint instead of using NodeSqlParser default parsing.

This PR also disables the EXPLAIN mode because they use the same endpoint and so there is a perf hit when called twice. We can optimize the endpoint.

Endpoint design:

/sql/validate

There are 2 possible paths:

  • catalog check : Checks the query against the database by using EXPLAIN {query}. Surfaces both syntax and catalog errors (invalid table_name etc.) but is not structured.
  • parse sql : Uses AST/backend parser to validate the query. This usually does not catch all errors but is cheaper than validating against a database. Only surfaces syntax errors, and not all syntax errors. Is structured.

When onlyParse is true, we just run the parse function, which is the aim of this PR. In the future, we want to optimize so that we can query once and get the complete response back.

🔍 Description of Changes

📋 Checklist

  • I have read the contributor guidelines.
  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable).
  • I have added tests for the changes made.
  • I have run the code and verified that it works as expected.

@vercel
Copy link

vercel bot commented Sep 24, 2025

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

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Sep 25, 2025 6:20pm

@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

2 similar comments
@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

mscolnick
mscolnick previously approved these changes Sep 25, 2025
@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@Light2Dark Light2Dark changed the title parse endpoint for sql parse endpoint for sql and custom sql parser Sep 25, 2025
@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

1 similar comment
@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

mscolnick
mscolnick previously approved these changes Sep 25, 2025
@Light2Dark Light2Dark marked this pull request as ready for review September 25, 2025 17:27
@Light2Dark Light2Dark marked this pull request as draft September 25, 2025 17:33
Light2Dark and others added 11 commits September 26, 2025 01:36
## 📝 Summary

<!--
Provide a concise summary of what this pull request is addressing.

If this PR fixes any issues, list them here by number (e.g., Fixes
#123).
-->

Uses get_connection_for_sql (so we catch DBAPI and other queryEngines).
Adds kernel tests for this codepath.

Update parse tests introduced by Myles, but note that they aren't
correct (many queries do not raise ParseErrors by duckdb)

## 🔍 Description of Changes

<!--
Detail the specific changes made in this pull request. Explain the
problem addressed and how it was resolved. If applicable, provide before
and after comparisons, screenshots, or any relevant details to help
reviewers understand the changes easily.
-->

## 📋 Checklist

- [x] I have read the [contributor
guidelines](https://github.com/marimo-team/marimo/blob/main/CONTRIBUTING.md).
- [ ] For large changes, or changes that affect the public API: this
change was discussed or approved through an issue, on
[Discord](https://marimo.io/discord?ref=pr), or the community
[discussions](https://github.com/marimo-team/marimo/discussions) (Please
provide a link if applicable).
- [x] I have added tests for the changes made.
- [x] I have run the code and verified that it works as expected.
@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@github-actions
Copy link

Breaking changes detected in the OpenAPI specification!

@Light2Dark
Copy link
Contributor Author

I removed the EXPLAIN extension for now, we can add it back after optimizing the endpoint.

@Light2Dark Light2Dark marked this pull request as ready for review September 25, 2025 18:30
@Light2Dark Light2Dark removed the request for review from akshayka September 25, 2025 18:30
@Light2Dark Light2Dark changed the title parse endpoint for sql and custom sql parser add parse function in /validate endpoint Sep 25, 2025
@Light2Dark Light2Dark changed the title add parse function in /validate endpoint add parse function in /validate endpoint for SQL Sep 25, 2025
@mscolnick mscolnick merged commit d881070 into main Sep 25, 2025
43 of 47 checks passed
@mscolnick mscolnick deleted the sham/parse-endpoint branch September 25, 2025 21:09
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants