-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Setup PyDough AST backreferences and hidden backreferences #21
Merged
knassre-bodo
merged 101 commits into
kian/ast_expr_collection_part_1
from
kian/setup_backreference
Nov 4, 2024
Merged
Changes from all commits
Commits
Show all changes
101 commits
Select commit
Hold shift + click to select a range
4c861a9
Setting up AST module, simple verifier, and basic test [RUN CI]
knassre-bodo 3144e94
Added deducer initial impl and tests
knassre-bodo 5b25976
Fixing AST invocation
knassre-bodo 4b5b0b0
Merge branch 'kian/setup_type_verifiers' into kian/setup_type_deducers
knassre-bodo 8c8eff0
Merge branch 'main' into kian/setup_type_verifiers
knassre-bodo bd4e5a2
Added messages to type test assertions
knassre-bodo be5bb3a
Updating after pulling from main [RUN CI]
knassre-bodo c4aa476
Merge branch 'kian/setup_type_verifiers' into kian/setup_type_deducers
knassre-bodo 0a2a3a8
Revisions [RUN CI]
knassre-bodo 2fd66f1
Added expression operators, binary operators, simple binop fixture-ba…
knassre-bodo 9fb5101
Fixing tpye inference
knassre-bodo 80c980f
Revising verifiers
knassre-bodo d70ae7d
Updating type deducers
knassre-bodo 2626fe9
Removing merge conflicts [RUN CI]
knassre-bodo 9cf3512
Adding operator registry import magic [RUN CI]
knassre-bodo a64349f
Adding operator registries, expression function calls
knassre-bodo 657a2d4
[RUN CI]
knassre-bodo 6331886
Initial impl WIP
knassre-bodo d35a934
Renaming expression function operators accordingly
knassre-bodo 5c7a018
Merge branch 'kian/setup_expression_operators' into kian/setup_expres…
knassre-bodo 1167458
Adding valid typing test
knassre-bodo 5273f04
Adding node builder, info class for tests, and refactoring imports
knassre-bodo d12058a
Fixing import bug
knassre-bodo dd4c3bc
Compressing test imports
knassre-bodo 1d501de
Refactoring metadata imports
knassre-bodo 5eff4ac
Updating metadata imports
knassre-bodo c2b7d7c
Minor revisions
knassre-bodo 8b92a7f
[RUN CI]
knassre-bodo 1337863
[RUN CI]
knassre-bodo 51b99d8
Updating types
knassre-bodo 624e277
[RUN CI]
knassre-bodo 5221fb0
Merge branch 'kian/update_metadata_imports' into kian/setup_type_dedu…
knassre-bodo 6262a60
Merge branch 'kian/update_metadata_imports' into kian/setup_type_veri…
knassre-bodo 01dad04
Adding module-level docstrings
knassre-bodo b4b13ff
Updating module level docstrings and inits [RUN CI]
knassre-bodo 5a8a7a0
Resolving upstream conflicts
knassre-bodo 275470d
Resolving conflicts
knassre-bodo 3b8e8d9
Adding class docstring
knassre-bodo b3877b7
Adding class docstring
knassre-bodo aac48f3
Merge branch 'kian/setup_type_verifiers' into kian/setup_type_deducers
knassre-bodo 0388683
Updating import paths [RUN CI]
knassre-bodo f9214cf
Resolivng conflicts and imports
knassre-bodo fedc9ea
Adding TODO strings
knassre-bodo 7f7fae4
Squishing imports
knassre-bodo e605f7b
Removing duplicate
knassre-bodo 39b6aae
Resolving conflicts
knassre-bodo 92bbb48
Adjusting imports
knassre-bodo 691e6ca
Adjusting testing setup with tpch_node_builder
knassre-bodo 66dfb07
Added more info/builder-based tests [RUN CI]
knassre-bodo 671a399
Adding/implementing collections semantics WIP
knassre-bodo c8438b9
Resolving conflicts [RUN CI]
knassre-bodo b87b0bc
Porting over collection files
knassre-bodo d1b788d
Resolving conflicts
knassre-bodo 10302fe
Pulling down from expression nodes
knassre-bodo 8095ee6
Removing collection logic
knassre-bodo 8748c7c
Resolving conflicts
knassre-bodo 2cc521b
Pushing subcollection components into next PR
knassre-bodo 9939abc
Resolving conflicts
knassre-bodo 7a86de3
Set up collection info pipelining for tests
knassre-bodo c7b8733
Minor update
knassre-bodo f293f5f
Minor update
knassre-bodo d2022bf
Renaming files [RUN CI]
knassre-bodo d6dd999
Experimenting with tree string
knassre-bodo 2d17449
Experimenting with tree string
knassre-bodo c9e1c15
Finished implementing subcollection and compound reasoning
knassre-bodo d46b369
Adjusting test utils [RUN CI]
knassre-bodo 7f7d2db
Adjusting tree string comment
knassre-bodo e2f013d
Cleaning up TestInfo classes
knassre-bodo dc610f6
Resolving conflicts
knassre-bodo 2495111
Fixing typo
knassre-bodo 65cb2b7
Fixing test info [RUN CI]
knassre-bodo a654dbb
Resolving conflicts [RUN CI]
knassre-bodo 3a3255a
Adding error tests [RUN CI]
knassre-bodo f4d5031
Added back reference classes
knassre-bodo c7317ad
Added string based tests and backreference error tests
knassre-bodo 2bcffe9
Pulling up downstream changes to expressions [RUN CI]
knassre-bodo 52ede47
Pulling downstream changes [RUN CI]
knassre-bodo 655ed42
Merge branch 'kian/init_collections' into kian/setup_collections
knassre-bodo dc24539
Pulling downstreamc changes and adding some comments
knassre-bodo 228ab0f
Adding more comments [RUN CI]
knassre-bodo cdd94a4
Merge branch 'kian/setup_collections' into kian/setup_backreference
knassre-bodo f3e4ce7
Pulling up minor binary operator change
knassre-bodo 13aa372
Test additions WIP
knassre-bodo 9cdd534
Adding more nested binop string tests [RUN CI]
knassre-bodo 852813c
Merge branch 'kian/setup_expression_nodes' into kian/init_collections
knassre-bodo 5df1983
Merge branch 'kian/init_collections' into kian/setup_collections
knassre-bodo 4a085f0
Resolving conflicts and pulling up downstream changes [RUN CI]
knassre-bodo dddc592
Refactoring drastically to have global context that table collections…
knassre-bodo 8c4c0b0
Resolving conflicts and updating subcollection class hierarchy
knassre-bodo 25b1809
Resolving conflcits after pulling down changes to subcollection class…
knassre-bodo 9f0fef6
Revisions [RUN CI]
knassre-bodo 45a2dec
Merge branch 'kian/init_collections' into kian/setup_collections
knassre-bodo 6319122
Revisions [RUN CI]
knassre-bodo 73d9324
Merge branch 'kian/setup_collections' into kian/setup_backreference
knassre-bodo afa93d3
resolving conflicts
knassre-bodo 209858b
Merge branch 'kian/ast_expr_collection_part_1' into kian/setup_collec…
knassre-bodo 25adaae
Resolving conflicts
knassre-bodo 261544a
Resolving conflicts (part 1)
knassre-bodo 68ed253
Resolving conflicts (part 2)
knassre-bodo 42ab7be
Merge branch 'kian/setup_collections' into kian/setup_backreference
knassre-bodo 15999dd
Resolving merge conflicts (part 1)
knassre-bodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
71 changes: 71 additions & 0 deletions
71
pydough/pydough_ast/collections/back_reference_collection.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
TODO: add file-level docstring | ||
""" | ||
|
||
__all__ = ["BackReferenceCollection"] | ||
|
||
from typing import Dict, Tuple | ||
from pydough.pydough_ast.abstract_pydough_ast import PyDoughAST | ||
from .collection_ast import PyDoughCollectionAST | ||
from pydough.pydough_ast.errors import PyDoughASTException | ||
from .collection_access import CollectionAccess | ||
|
||
|
||
class BackReferenceCollection(CollectionAccess): | ||
""" | ||
The AST node implementation class representing a subcollection of an | ||
ancestor collection. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
parent: PyDoughCollectionAST, | ||
term_name: str, | ||
back_levels: int, | ||
): | ||
if not (isinstance(back_levels, int) and back_levels > 0): | ||
raise PyDoughASTException( | ||
f"Expected number of levels in BACK to be a positive integer, received {back_levels!r}" | ||
) | ||
self._term_name: str = term_name | ||
self._back_levels: int = back_levels | ||
for _ in range(back_levels): | ||
self._ancestor = self._ancestor.ancestor_context | ||
if self._ancestor is None: | ||
msg: str = "1 level" if back_levels == 1 else f"{back_levels} levels" | ||
raise PyDoughASTException( | ||
f"Cannot reference back {msg} above {parent!r}" | ||
) | ||
self._collection_access: CollectionAccess = self._ancestor.get_term(term_name) | ||
super().__init__(self._collection_access.collection, parent) | ||
|
||
@property | ||
def back_levels(self) -> int: | ||
""" | ||
The number of levels upward that the backreference refers to. | ||
""" | ||
return self._back_levels | ||
|
||
@property | ||
def term_name(self) -> str: | ||
""" | ||
The name of the subcollection being accessed from the ancestor. | ||
""" | ||
return self._term_name | ||
|
||
@property | ||
def collection_access(self) -> CollectionAccess: | ||
""" | ||
The collection access property of the ancestor that BACK points to. | ||
""" | ||
return self._collection_access | ||
|
||
@property | ||
def properties(self) -> Dict[str, Tuple[int | None, PyDoughAST]]: | ||
return self.collection_access.properties | ||
|
||
def to_string(self) -> str: | ||
return f"BACK({self.back_levels}).{self._subcollection.to_string()}" | ||
|
||
def to_tree_form(self) -> None: | ||
raise NotImplementedError |
This file contains 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
48 changes: 48 additions & 0 deletions
48
pydough/pydough_ast/collections/hidden_back_reference_collection.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
""" | ||
TODO: add file-level docstring | ||
""" | ||
|
||
__all__ = ["HiddenBackReferenceCollection"] | ||
|
||
|
||
from .collection_ast import PyDoughCollectionAST | ||
from .back_reference_collection import BackReferenceCollection | ||
from .collection_access import CollectionAccess | ||
|
||
|
||
class HiddenBackReferenceCollection(BackReferenceCollection): | ||
""" | ||
The AST node implementation class representing a subcollection of an | ||
ancestor collection. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
compound: PyDoughCollectionAST, | ||
ancestor: PyDoughCollectionAST, | ||
alias: str, | ||
term_name: str, | ||
back_levels: int, | ||
): | ||
self._term_name: str = term_name | ||
self._back_levels: int = back_levels | ||
self._ancestor: PyDoughCollectionAST = ancestor | ||
self._subcollection: PyDoughCollectionAST = self._ancestor.get_term(term_name) | ||
self._alias: str = alias | ||
self._collection_access: CollectionAccess = self._ancestor.get_term(term_name) | ||
super(BackReferenceCollection, self).__init__( | ||
self._collection_access.collection, ancestor | ||
) | ||
|
||
@property | ||
def alias(self) -> str: | ||
""" | ||
The alias that the back reference uses. | ||
""" | ||
return self._alias | ||
|
||
def to_string(self) -> str: | ||
return f"{self.parent.to_string()}.{self.alias}" | ||
|
||
def to_tree_string(self) -> str: | ||
raise NotImplementedError |
This file contains 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
76 changes: 76 additions & 0 deletions
76
pydough/pydough_ast/expressions/back_reference_expression.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
TODO: add file-level docstring | ||
""" | ||
|
||
__all__ = ["BackReferenceExpression"] | ||
|
||
from . import PyDoughExpressionAST | ||
from pydough.types import PyDoughType | ||
from pydough.pydough_ast.collections import PyDoughCollectionAST | ||
from pydough.pydough_ast.errors import PyDoughASTException | ||
from .reference import Reference | ||
|
||
|
||
class BackReferenceExpression(Reference): | ||
""" | ||
The AST node implementation class representing a reference to a term in | ||
the ancestor context. | ||
""" | ||
|
||
def __init__( | ||
self, collection: PyDoughCollectionAST, term_name: str, back_levels: int | ||
): | ||
if not (isinstance(back_levels, int) and back_levels > 0): | ||
raise PyDoughASTException( | ||
f"Expected number of levels in BACK to be a positive integer, received {back_levels!r}" | ||
) | ||
self._collection: PyDoughCollectionAST = collection | ||
self._term_name: str = term_name | ||
self._back_levels: int = back_levels | ||
self._ancestor: PyDoughCollectionAST = collection | ||
for _ in range(back_levels): | ||
self._ancestor = self._ancestor.ancestor_context | ||
if self._ancestor is None: | ||
msg: str = "1 level" if back_levels == 1 else f"{back_levels} levels" | ||
raise PyDoughASTException( | ||
f"Cannot reference back {msg} above {collection!r}" | ||
) | ||
self._expression: PyDoughExpressionAST = self._ancestor.get_term(term_name) | ||
|
||
@property | ||
def back_levels(self) -> int: | ||
""" | ||
The number of levels upward that the backreference refers to. | ||
""" | ||
return self._back_levels | ||
|
||
@property | ||
def ancestor(self) -> PyDoughCollectionAST: | ||
""" | ||
The specific ancestor collection that the ancestor refers to. | ||
""" | ||
return self._ancestor | ||
|
||
@property | ||
def expression(self) -> PyDoughExpressionAST: | ||
""" | ||
The original expression that the reference refers to. | ||
""" | ||
return self._expression | ||
|
||
@property | ||
def pydough_type(self) -> PyDoughType: | ||
return self.expression.pydough_type | ||
|
||
@property | ||
def is_aggregation(self) -> bool: | ||
return self.expression.is_aggregation | ||
|
||
def requires_enclosing_parens(self, parent: PyDoughExpressionAST) -> bool: | ||
return False | ||
|
||
def to_string(self) -> str: | ||
return f"BACK({self.back_levels}).{self.term_name}" | ||
|
||
def equals(self, other: "BackReferenceExpression") -> bool: | ||
return super().equals(other) and self.ancestor.equals(other.ancestor) |
42 changes: 42 additions & 0 deletions
42
pydough/pydough_ast/expressions/hidden_back_reference_expression.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" | ||
TODO: add file-level docstring | ||
""" | ||
|
||
__all__ = ["HiddenBackReferenceExpression"] | ||
|
||
from . import PyDoughExpressionAST | ||
from pydough.pydough_ast.collections import PyDoughCollectionAST | ||
from .back_reference_expression import BackReferenceExpression | ||
|
||
|
||
class HiddenBackReferenceExpression(BackReferenceExpression): | ||
""" | ||
The AST node implementation class representing a reference to a term in | ||
the ancestor context through the lens of a compound relationship's | ||
inherited properties. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
collection: PyDoughCollectionAST, | ||
ancestor: PyDoughCollectionAST, | ||
alias: str, | ||
term_name: str, | ||
back_levels: int, | ||
): | ||
self._collection: PyDoughCollectionAST = collection | ||
self._alias: str = alias | ||
self._term_name: str = term_name | ||
self._back_levels: int = back_levels | ||
self._ancestor: PyDoughCollectionAST = ancestor | ||
self._expression: PyDoughExpressionAST = self._ancestor.get_term(term_name) | ||
|
||
@property | ||
def alias(self) -> str: | ||
""" | ||
The alias that the back reference uses. | ||
""" | ||
return self._alias | ||
|
||
def to_string(self) -> str: | ||
return f"HiddenBackReferenceExpression[{self.back_levels}:{self.term_name}]" |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly, only used inside compounds.