feat(nosql): diagnose ORDER BY inside a subquery#3148
Open
bk201- wants to merge 1 commit into
Open
Conversation
Azure Cosmos DB rejects ORDER BY inside any subquery (FIRST/LAST/ARRAY/EXISTS/(SELECT ...)/FROM (...)) with HTTP 400, even though the grammar accepts it and the docs do not mention the restriction. Add an AST-based ORDER_BY_IN_SUBQUERY diagnostic (severity Error) wired into single- and multi-query diagnostics, plus unit tests, a keyword-doc note, and reclassify the SQ-05/SQ-06 fixtures from emulator-only to a Cosmos DB language limitation. Refs Azure/azure-cosmos-db-emulator-docker#311.
Contributor
🔬 NoSQL language-service integrationCommit: c450cb6 🧪 Result
📥 Artifacts (run)
|
Contributor
🔨 Build, Lint & Test🔗 Source
📦 Package Information
🧪 Test Results
📥 Artifacts (run)✅ Build StatusBuild and local tests passed. See sibling comments below for E2E and NoSQL integration results. |
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.
Summary
Azure Cosmos DB NoSQL does not support
ORDER BYinside a subquery —FIRST(…),LAST(…),ARRAY(…),EXISTS(…), scalar(SELECT …), andFROM (SELECT …). Thebackend rejects such queries at execution time with HTTP 400, even though:
sql.ygrammar accepts them (every subquery embeds a fullsql_query,which carries an optional
ORDER BY), andBecause it is a semantic (engine) rule rather than a grammatical one, the parser can't
catch it — so this PR adds a static diagnostic instead, surfacing the error in the editor
before the user runs the query.
Confirmed against production Cosmos DB: every subquery form with
ORDER BYreturns 400,while the same subqueries without
ORDER BY(and a top-levelORDER BY) work.Refs Azure/azure-cosmos-db-emulator-docker#311 (originally mis-reported as "
FIRST()unsupported"; the real discriminator is the nested
ORDER BY).Changes
src/diagnostics/orderByInSubquery.ts— AST walk that flags anORDER BYon any non-root query. Takes the already-parsed AST (no re-parse, no importcycle); reports on the
ORDER BYclause range.SqlLanguageService.getDiagnostics(single- and multi-query) asORDER_BY_IN_SUBQUERY, severity Error. Exported from the package entry point.src/diagnostics/orderByInSubquery.test.ts(15) — FIRST/LAST/ARRAY/EXISTS/(SELECT …)/FROM (…), nested and multiple occurrences, negative cases, and serviceintegration (single + multi-query offsets).
ORDER_BYkeyword doc;SQ-05/SQ-06reclassified intest-suite.mdfrom "emulator-only known limitation" to a Cosmos DB languagelimitation, with the diagnostic referenced.
Validation
npm run build(tsc) — clean.npm run lint— oxlint + eslint, 0 errors.npm run prettier-fix— applied.No user-facing string changes outside the diagnostic message.