Skip to content

feat(cosmosdb): improve grammar compatibility#63

Merged
rebelice merged 1 commit intomainfrom
vk/7113-improve-cosmosdb
Mar 19, 2026
Merged

feat(cosmosdb): improve grammar compatibility#63
rebelice merged 1 commit intomainfrom
vk/7113-improve-cosmosdb

Conversation

@h3n4l
Copy link
Member

@h3n4l h3n4l commented Mar 19, 2026

Summary

  • Add missing CosmosDB SQL syntax: ?? coalesce, <> inequality, LIKE ESCAPE, ARRAY(subquery), -- line comments, Infinity/NaN constants, c[@param] bracket parameter access
  • Rework FROM clause to support ROOT, subroot paths (container.property), IN iteration, subqueries, and flexible JOINs
  • Expand keyword-as-identifier support: 17 keywords usable as property names after dot (e.g., c.select, c.from, c.where)
  • Add ORDER BY RANK for full-text search syntax

References

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

  • All 37 parser tests pass (23 existing + 14 new example SQL files)
  • Emulator validation for: ??, <>, LIKE ESCAPE, ARRAY(subquery), FROM ROOT, FROM (subquery), -- comments, JOIN IN

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings March 19, 2026 09:09
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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/JOIN grammar to support additional FROM sources (e.g., ROOT, subroot paths, IN iteration, subqueries).
  • Add new cosmosdb/examples/*.sql fixtures 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 rebelice merged commit 42a9a5d into main Mar 19, 2026
9 checks passed
@rebelice rebelice deleted the vk/7113-improve-cosmosdb branch March 19, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants