[Refactor] Query Parser Fix After AST Support#100
Conversation
There was a problem hiding this comment.
Pull request overview
This PR refactors the SQL-to-AST query parser to handle a broader set of mo_sql_parsing constructs (e.g., DISTINCT/DISTINCT ON, IN literal lists, CASE, INTERVAL/EXTRACT, NULL/IS NULL), and updates the test suite to re-enable many previously disabled parser/AST equality assertions.
Changes:
- Expanded
core/query_parser.pyto parse additional SQL constructs into the project’s AST node types (e.g.,ListNode,CaseNode,IntervalNode,DataTypeNode, DISTINCT ON support). - Adjusted alias handling across clauses (notably GROUP BY / WHERE comments and resolution behavior).
- Re-enabled many
tests/test_query_parser.pyassertions, while leavingtest_basic_parseandtest_query_42effectively disabled pending design decisions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| tests/test_query_parser.py | Re-enables most parser-vs-expected-AST assertions, but leaves two key tests disabled via commented asserts. |
| core/query_parser.py | Adds parsing support for DISTINCT(+ON), IN lists/subqueries, NULL/IS NULL, CASE, INTERVAL, EXTRACT, and tweaks alias resolution logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR refactors and extends the SQL-to-AST query parser to support more complex query patterns emitted by mo_sql_parsing, with the goal of turning previously-disabled parser tests back on.
Changes:
- Expanded
QueryParserto handle additional SQL constructs (e.g.,DISTINCT/DISTINCT ON,INliteral lists,INTERVAL,EXTRACT,CASE,NULLnormalization). - Adjusted alias resolution behavior across clauses (notably
GROUP BY,ORDER BY, andWHERE) to better match expected AST semantics. - Re-enabled many previously-commented test assertions (while leaving a couple still disabled).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
core/query_parser.py |
Adds parsing support for more AST node types and improves clause parsing/alias resolution to satisfy more real-world queries. |
tests/test_query_parser.py |
Re-enables many parser equality assertions; still has two key tests with assertions commented out. |
data/asts.py |
Minor comment/TODO update on GROUP BY ordinal handling in Query 42 expected AST. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Overview
This PR updates the query parser logic to support more complex test cases. All existing test cases now pass, except for the two listed in the following section.
Remaining Questions / TODOs
test_basic_parse: Should we treatd.namein theGROUP BYclause as a new node, instead of using the aliasdept_namebased on our previous discussion?test_query_42: The original query is-EXTRACT(DOW FROM created_at). IsOperatorNode(LiteralNode(0), "-", extract_dow)(becomes0 - EXTRACT(DOW FROM created_at)) an acceptable translation? (I assume no)UNION