LYT-515 | Lex unquoted negative numeric literals as signed literals in FilterQL - #58
Draft
onkarj-47 wants to merge 1 commit into
Draft
LYT-515 | Lex unquoted negative numeric literals as signed literals in FilterQL#58onkarj-47 wants to merge 1 commit into
onkarj-47 wants to merge 1 commit into
Conversation
FilterQL rejected unquoted `-1`/`-1.5` in `=` comparisons and hard-failed on them in `IN (...)` lists, while the quoted form parsed fine. Gate the lexer's `-` handling on lastToken so a `-` in a value position (after a comparator, operator, `(`, `,`, logic, IN/BETWEEN, or start-of-input) lexes as one signed TokenInteger/TokenFloat instead of TokenMinus, so it parses to a single *expr.NumberNode and round-trips to a bare `-1` instead of `- (1)`. Binary subtraction is unaffected. Co-authored-by: Onkar Jaliminche <onkar.jaliminche@contentstack.com> Co-authored-by: Vedant Karle <vedant.karle@contentstack.com> Co-authored-by: Claude <noreply@anthropic.com>
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.
🤖 Opened by an AI agent — not a person. This PR was created by the
lytics-developer-agentskill (Claude, Anthropic) running unattended. It shows under the assignee's GitHub account because it uses their token, but a human did not hand-write it — and comment replies on this PR from this account are also posted by the agent, not typed by a person. Review, approval, and merge stay human decisions; the agent never marks the PR ready-for-review and never merges.Merge order
This is the producer in a two-PR change for LYT-515:
qlbridgedependency to this fix and adds the lio-side coercion + regression tests. It currently pins the fix branch commit (e136cbab2); re-pin to this PR's squash-merge commit before merging lio.What was broken
FilterQL / SegmentQL rejected unquoted negative numeric literals in value positions, while the quoted form was accepted. This blocked the customer-facing remainder of LYT-486 (P&G escalation). Two distinct failure modes, both rooted here in the lexer:
FILTER visitct IN (-1) FROM userUnrecognized input)LexListOfArgsbacks up on-→LexExpressionemits a standaloneTokenMinus, desyncing the array token streamFILTER visitct IN (-1, 3) FROM userFILTER visitct = -1 FROM userUnaryNode{Minus, Number}→ printed as- (1)-is torn off asTokenMinusbefore number-lookaheadThe number scanner already accepted a leading sign (
scanNumericOrDuration), but that path was never reached in comparison-RHS /IN-list positions.The fix
In
lex/lexer.go, when a-appears in a value position — the previous emitted token is a comparator, arithmetic operator,(,,, logic op,IN/BETWEEN, or start-of-input (TokenNil) — and the next rune is a digit (or.+digit), lex it as a single signed numeric token instead ofTokenMinus. Gating is strictly onl.lastToken.T, so binary subtraction (a - b, where the previous token is an identity/number/value/)) is unchanged — important becauseLexExpressionis shared with the SQL dialect.A matching narrow fix in
LexListOfArgsre-pushes the list continuation before delegating a value-position-toLexExpression, so multi-element lists likeIN (-1, 3)resolve the trailing,/)correctly.Result
= -1,city = -1,= -1.5,IN (-1),IN (-1, 3),IN (-1)on string-typed fields all parse; each negative is a single*expr.NumberNodewhose.Textcarries the sign;.String()canonicalizes to the bare signed form (FILTER visitct IN (-1) FROM user, never- (1)) and re-parses idempotently — closing the stored-QL round-trip asymmetry from the ticket. Positive, quoted, and binary-minus behavior is unchanged.Testing
rel/parse_filterql_test.go(=int/float,INsingle/multi, int- and string-named fields; asserts node type and stable round-trip) and inlex/lexer_test.go/lex/dialect_filterql_test.go(tokenization + binary-minus-unchanged).go test -race ./...(26 packages).Known observations (not changed here)
go vet ./...reports a pre-existingunreachable codeattestutil/testsuite.go:215— present on the base commit, untouched by this PR, and not part of this repo's CI (.github/workflows/test.ymlrunsgo test -race ./...). Left alone to keep this PR scoped to the bug fix.Files
lex/lexer.go— value-position signed-literal lexing (valueExpectedTokens,numericAfterSign(), theLexExpression/LexListOfArgs-handling).lex/lexer_test.go,lex/dialect_filterql_test.go,rel/parse_filterql_test.go— tests.Generated by Claude Code