-
Notifications
You must be signed in to change notification settings - Fork 50
refactor: Reimplement implicit joiner at expression layer #436
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
Conversation
3d6becb
to
5bd7a36
Compare
5bd7a36
to
415b6c0
Compare
bigframes/core/expression.py
Outdated
@@ -81,6 +81,12 @@ def output_type( | |||
) -> dtypes.ExpressionType: | |||
... | |||
|
|||
@abc.abstractmethod | |||
def bind_variables( |
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.
Could we get a docstring for this, please?
I assume this returns a version of the expression where free variables are replaced with the expressions in the bindings mapping?
What does bind_all
control? Looks like it raises a ValueError if there are any UnboundVariables left?
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.
On second look, I see that this is maybe a recursive sort of function where the variables bind themselves? Though maybe the effect is the same where free variables are replaced with expressions.
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.
removed bind_all
parameter as it was always set. And yes, this method replaces all the variables in the expression with the corresponding expression given in the bindings
input.
bigframes/core/ordering.py
Outdated
class OrderingExpression: | ||
"""A more flexible version of OrderingColumnReference.""" | ||
|
||
# TODO: Maybe migrate BFET to use this? |
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.
Could we add a little more detail to this TODO, please?
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.
extended the todo
bigframes/core/ordering.py
Outdated
@@ -61,6 +63,26 @@ def with_reverse(self): | |||
) | |||
|
|||
|
|||
@dataclass(frozen=True) | |||
class OrderingExpression: | |||
"""A more flexible version of OrderingColumnReference.""" |
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.
Let's lead in the first line what the purpose is. e.g. "Defines ordering for an expression" or something like that.
Also, more flexible in what way? That could be a note in the docstring body.
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.
added more info to docstring
bigframes/core/ordering.py
Outdated
direction: OrderingDirection = OrderingDirection.ASC | ||
na_last: bool = True | ||
|
||
def remap_names(self, mapping: dict[str, str]): |
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 needs a docstring. I'm not 100% certain the purpose.
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 type annotations, looks like we can use Self
here for this builder pattern.
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.
wasn't able to get this working. Think we need to be on python 3.11
bigframes/core/ordering.py
Outdated
self.scalar_expression.rename(mapping), self.direction, self.na_last | ||
) | ||
|
||
def with_reverse(self): |
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.
Ditto
def with_reverse(self): | |
def with_reverse(self) -> Self: |
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 just put the explicit type in new revision as couldn't get Self
working. This would be definitely helpful for abstract base classes though.
bigframes/core/rewrite.py
Outdated
|
||
|
||
@dataclasses.dataclass | ||
class NormalizedSelect: |
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.
Sorry, normalized in what way? Let's do a docstring here too.
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.
Not really normalized so much as it is the result of squashing together projections, filters and orderbys as much as possible
new_ordering = tuple(expr.with_reverse() for expr in self.ordering) | ||
return NormalizedSelect(self.root, self.columns, self.predicate, new_ordering) | ||
|
||
def order_with(self, by: Tuple[order.OrderingColumnReference, ...]): |
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.
Why not take an OrderingExpression
here? Seems a bit odd to add new interfaces that use something that might be deprecated.
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.
We are trying to consume and OrderByNode
here, and that still uses OrderingColumnReference
. I think we might want to migrate these nodes to use the more general OrderingExpression
, but that would substantially expand the scope of this PR.
bigframes/core/__init__.py
Outdated
) | ||
if allow_row_identity_join: | ||
as_selection = bigframes.core.rewrite.rewrite_join(join_node) |
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.
Why doesn't rewrite_join
return join_node
if it can't rewrite? Seems like this should be called maybe_join
like the lower layer does if it might return None
.
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.
done
bigframes/core/rewrite.py
Outdated
if (self.root == right.root) and all( | ||
l_expr == r_expr for l_expr, r_expr in zip(l_join_exprs, r_join_exprs) | ||
): |
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.
Seems we could reduce some nesting if we did the inverse of this and exit early. go/tott/651
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.
done
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.
Thanks!
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕