fix(backend): insert project_id filter before ORDER BY/GROUP BY/LIMIT#280
Merged
chiragSharmaD11 merged 6 commits intomainfrom Mar 9, 2026
Merged
fix(backend): insert project_id filter before ORDER BY/GROUP BY/LIMIT#280chiragSharmaD11 merged 6 commits intomainfrom
chiragSharmaD11 merged 6 commits intomainfrom
Conversation
appendProjectId was blindly appending AND project_id at the query end, which produced invalid SQL when ORDER BY, GROUP BY, or LIMIT was present. Made-with: Cursor
There was a problem hiding this comment.
Orca Security Scan Summary
| Status | Check | Issues by priority | |
|---|---|---|---|
| Infrastructure as Code | View in Orca | ||
| SAST | View in Orca | ||
| Secrets | View in Orca | ||
| Vulnerabilities | View in Orca |
Use WHERE instead of AND when the query has no existing WHERE clause, preventing invalid SQL like "SELECT ... FROM table AND project_id = ..." Made-with: Cursor
Call appendProjectId directly instead of going through submitQuery, removing coupling to SqlQueryValidator and mock boilerplate. Made-with: Cursor
yasir6jan
approved these changes
Mar 9, 2026
…tion insertion Extend TRAILING_CLAUSE_PATTERNS in both QueryServiceImpl.appendProjectId and QueryTimestampEnricher.addWhereClause to cover HAVING, OFFSET, UNION, INTERSECT, and EXCEPT — preventing filters from being appended after these clauses and producing invalid SQL. Made-with: Cursor
Made-with: Cursor
shubhamguptadream11
approved these changes
Mar 9, 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
Fix
appendProjectIdinQueryServiceImplto insert theproject_idfilter before trailing SQL clauses (ORDER BY, GROUP BY, LIMIT) instead of blindly appending at the query end.Context / Motivation
Queries with
ORDER BY,GROUP BY, orLIMITclauses were failing with Athena parse errors becauseAND project_id = '...'was appended after these clauses, producing invalid SQL like:Error:
mismatched input 'AND'. Expecting: ',', 'FETCH', 'LIMIT', 'NULLS', 'OFFSET', <EOF>What Changed
appendProjectIdinQueryServiceImplto find the earliest trailing clause position (ORDER BY, GROUP BY, LIMIT) and insert the project_id filter before itfindTrailingClausePositionhelper with precompiled regex patterns@Nested AppendProjectIdclass covering ORDER BY, GROUP BY, LIMIT, combined clauses, and the no-trailing-clause fallbackScreenshots / Recordings (UI only)