-
Notifications
You must be signed in to change notification settings - Fork 1
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
Set up PyDough AST module with basic abstract classes and simple type verifiers #13
Conversation
assert pydough_type.json_string == type_string | ||
assert ( | ||
repr(pydough_type) == repr_string | ||
), "parsed type does not match expected repr() string" |
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.
For consistency.
tests/test_type_verifiers.py
Outdated
@pytest.mark.parametrize( | ||
"verifier, args", | ||
[pytest.param(AllowAny(), [], id="allow_any-empty_args")], | ||
) | ||
def test_verification(verifier: TypeVerifier, args: List[PyDoughAST]): | ||
""" | ||
Checks that verifiers accept certain arguments without raising an exception | ||
""" | ||
verifier.accepts(args) |
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.
A dumb test, but setting up the framework & verifying that the imports don't cause a build error.
@@ -0,0 +1,38 @@ | |||
""" |
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.
This file will eventually be filled by a lot of verifiers that borrow a lot of ideas from Calcite, such as:
- Signatures
- Compounds
- Allow a specific type
- Require membership to a family
- Require matches across arguments
- Variadics
- Literal matching (e.g.
DATE('now', 'start of month', '-3 months')
)
However, these will usually be loose requirements that represent a minimal amount of universally accepted behavior (sound-but-not-complete), such as:
x + y
requires the arguments to be numericLOWER(...)
requires the argument to be a string- Datetime extraction functions require a datetime argument.
- Usually, if the type is unknown, just allow it.
The main thing is making sure that things that should be expressions vs collections are actually expressions vs collections (e.g. no calling COALESCE
on tpch.Parts
). That kind of check will come into play later.
from abc import ABC, abstractmethod | ||
|
||
|
||
class PyDoughAST(ABC): |
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.
Once I start adding implementations, will create a builder class for ease of testing.
@@ -0,0 +1,46 @@ | |||
""" | |||
TODO: add file-level docstring. | |||
""" |
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.
Some simple tests for now. Will become far more elaborate once I have node builders.
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.
LGTM! Thanks @knassre-bodo
def __eq__(self, other): | ||
return self.equals(other) | ||
|
||
@abstractmethod |
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.
I assume this is just to make an abstract method since you can't make __eq__
abstract?
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.
More or less, yes
Defines the PyDough AST module with the following:
PyDoughAST
for all AST nodesPyDoughASTException
exception classPyDoughExpressionAST
for all AST expression nodes