Skip to content

feat(mongodb): accept string arguments in Int32/NumberInt helpers#64

Merged
rebelice merged 1 commit intomainfrom
vk/0465-byt-9080-mongodb
Mar 24, 2026
Merged

feat(mongodb): accept string arguments in Int32/NumberInt helpers#64
rebelice merged 1 commit intomainfrom
vk/0465-byt-9080-mongodb

Conversation

@h3n4l
Copy link
Member

@h3n4l h3n4l commented Mar 24, 2026

Summary

  • Allow Int32("123") and NumberInt("456") syntax in the MongoDB shell grammar, matching the existing Long/NumberLong behavior
  • This aligns with real mongosh usage where users pass string arguments to numeric type constructors

Context

Bytebase uses gomongo to translate mongosh queries to native Go driver calls. Telemetry showed Int32("string") as the most frequent compatibility failure (BYT-9080). The Long/NumberLong helpers already accept string arguments — this change makes Int32/NumberInt consistent.

Changes

  • MongoShellParser.g4: Changed int32Helper rule from NUMBER to (NUMBER | stringLiteral)
  • Regenerated parser

Test plan

  • make build && make test in mongodb/ directory passes
  • gomongo integration tests pass with this grammar change

🤖 Generated with Claude Code

Int32("123") and NumberInt("456") are valid in mongosh but the grammar
only accepted NUMBER tokens. Align with Long/NumberLong which already
supports both forms.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 24, 2026 03:54
@rebelice rebelice merged commit 3b4d6e7 into main Mar 24, 2026
7 checks passed
@rebelice rebelice deleted the vk/0465-byt-9080-mongodb branch March 24, 2026 03:56
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 MongoDB shell ANTLR grammar to accept string arguments for Int32(...) / NumberInt(...) helpers (e.g., Int32("123")), aligning behavior with existing Long(...) / NumberLong(...) parsing and improving mongosh compatibility.

Changes:

  • Expanded the int32Helper grammar rule to accept (NUMBER | stringLiteral) instead of only NUMBER.
  • Regenerated the Go parser output to reflect the grammar update.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
mongodb/MongoShellParser.g4 Updates int32Helper rule to accept string literals for Int32/NumberInt constructors.
mongodb/mongoshell_parser.go Regenerated parser code to support the updated int32Helper alternative (NUMBER or string literal).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +822 to +824
// Int32(n), Int32("n"), NumberInt(n), NumberInt("n")
int32Helper
: (INT32 | NUMBER_INT) LPAREN NUMBER RPAREN
: (INT32 | NUMBER_INT) LPAREN (NUMBER | stringLiteral) RPAREN
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

The grammar now accepts Int32("n") / NumberInt("n"), but the parser test suite (driven by mongodb/examples/*.js) currently only exercises numeric Int32(100) / NumberInt(100). Please add examples for the quoted-string forms (e.g., in examples/helper_functions.js) so this new syntax is covered and regressions are caught.

Copilot uses AI. Check for mistakes.
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