Skip to content

Conversation

@colinthebomb1
Copy link
Collaborator

Overview:

This PR improves the node ast

Code Changes:

  • Added alias to FunctionNode, allows for cases like SELECT COUNT(*) as emp_count
  • Changed set to list in Select, From, Where, and Having nodes, allowing for order of items in clauses to be maintained
  • Added sort parameter in OrderBy node and created OrderByItemNode to allow more functionality in ORDER BY statements

@HazelYuAhiru
Copy link
Collaborator

HazelYuAhiru commented Nov 12, 2025

Code Changes for the Parser

  • Added __eq__ and __hash__ methods to several classes to enable proper comparison in parser test cases.
  • Added a simple Join node structure for the Join required in the parser baseline test case.

@colinthebomb1 Could you take a look at the new code I added? Thanks a lot!

HazelYuAhiru
HazelYuAhiru previously approved these changes Nov 12, 2025
core/ast/node.py Outdated
class OrderByNode(Node):
"""ORDER BY clause node"""
def __init__(self, _items: List['Node'], **kwargs):
def __init__(self, _items: List['Node'], _sort: Optional[str] = None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above. Since sort approach (DESC, ASC) are two SQL keywords, should we also use enum?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

super().__init__(NodeType.HAVING, children=_predicates, **kwargs)


class OrderByItemNode(Node):
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the difference between OrderByItemNode and OrderByNode?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OrdrByItemNode is for single items in ORDER BY clauses like
OrderByItemNode(ColumnNode("salary"), _sort = SortOrder.DESC).
OrderByNode is used to build full ORDER BY clauses formed by multiple OrderByItemNode like

OrderByNode([
    OrderByItemNode(ColumnNode("salary"), _sort=SortOrder.DESC), 
    OrderByItemNode(ColumnNode("age"), _sort=SortOrder.ASC)
])

@colinthebomb1
Copy link
Collaborator Author

@HazelYuAhiru, other than the JoinType enum that Qiushi pointed out, your changes LGTM! I added the eq and hash for the nodes I was working on, too.

@colinthebomb1 colinthebomb1 merged commit 31ff011 into main Nov 20, 2025
2 checks passed
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.

4 participants