feat(cosmosdb): improve grammar compatibility#63
Merged
Conversation
…ork, and more Add missing CosmosDB SQL syntax features validated against official docs, reference grammars (Azure ANTLR, Vercel PEG), and CosmosDB emulator. Lexer: ESCAPE, ARRAY, ROOT, RANK keywords; <> and ?? operators; -- line comments; Infinity/NaN constants (case-sensitive). Parser: ?? coalesce at OR precedence; ARRAY(subquery); LIKE ESCAPE; parameter in bracket access c[@param]; <> inequality. FROM clause: reworked to support ROOT, subroot paths (container.property), IN iteration (s IN container.sizes), subqueries, flexible JOINs. Keywords as property names: 17 keywords usable after dot (c.select, c.from, etc). ORDER BY RANK for full-text search syntax. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the CosmosDB ANTLR grammar (lexer + parser) to accept additional Cosmos DB NoSQL SQL syntax variants and adds new example SQL files to exercise those grammar paths via the existing parser test harness.
Changes:
- Extend lexer/parser grammar to support additional operators/constructs (e.g.,
??,<>,LIKE ... ESCAPE,ARRAY(subquery),ROOT,RANK,--comments,Infinity/NaN, bracket parameter indexing). - Rework
FROM/JOINgrammar to support additionalFROMsources (e.g.,ROOT, subroot paths,INiteration, subqueries). - Add new
cosmosdb/examples/*.sqlfixtures covering the new syntax.
Reviewed changes
Copilot reviewed 17 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cosmosdb/CosmosDBLexer.g4 | Adds new keywords/tokens (ESCAPE, ARRAY, ROOT, RANK, ??, <>, Infinity, NaN, -- line comments). |
| cosmosdb/CosmosDBParser.g4 | Updates grammar rules for ORDER BY RANK, expanded FROM/JOIN forms, LIKE ... ESCAPE, ?? coalesce, bracket-parameter access, ARRAY(subquery), and new constants/operators. |
| cosmosdb/cosmosdb_lexer.go | Regenerated Go lexer to reflect updated lexer grammar token set. |
| cosmosdb/examples/array_subquery.sql | Example for ARRAY(subquery) expression. |
| cosmosdb/examples/bracket_parameter.sql | Example for c[@param] bracket parameter access. |
| cosmosdb/examples/coalesce_operator.sql | Example for ?? coalesce operator. |
| cosmosdb/examples/from_in_iteration.sql | Example for FROM <id> IN <path> iteration. |
| cosmosdb/examples/from_root.sql | Example for FROM ROOT source. |
| cosmosdb/examples/from_subquery.sql | Example for FROM (subquery) AS alias. |
| cosmosdb/examples/from_subroot.sql | Example for dotted subroot container path (container.property). |
| cosmosdb/examples/fulltext_search.sql | Example for ORDER BY RANK ... full-text-search-style ordering. |
| cosmosdb/examples/infinity_nan.sql | Example for Infinity / NaN constants. |
| cosmosdb/examples/join_subquery.sql | Example for JOIN <id> IN <expr> join iteration. |
| cosmosdb/examples/keyword_property_names.sql | Example for keyword-like property access patterns. |
| cosmosdb/examples/like_escape.sql | Example for LIKE ... ESCAPE .... |
| cosmosdb/examples/line_comment.sql | Example for -- line comments. |
| cosmosdb/examples/not_equal_diamond.sql | Example for <> not-equal operator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rebelice
approved these changes
Mar 19, 2026
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
??coalesce,<>inequality,LIKE ESCAPE,ARRAY(subquery),--line comments,Infinity/NaNconstants,c[@param]bracket parameter accessROOT, subroot paths (container.property),INiteration, subqueries, and flexible JOINsc.select,c.from,c.where)ORDER BY RANKfor full-text search syntaxReferences
Validation
All new syntax features validated against the CosmosDB emulator (Docker
mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:vnext-preview). Full-text search functions are grammar-only (emulator doesn't support them yet).Test plan
??,<>,LIKE ESCAPE,ARRAY(subquery),FROM ROOT,FROM (subquery),--comments,JOIN IN🤖 Generated with Claude Code