Skip to content

refactor: Simplify join node definition #966

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

Merged
merged 8 commits into from
Sep 11, 2024
Merged

refactor: Simplify join node definition #966

merged 8 commits into from
Sep 11, 2024

Conversation

TrevorBergeron
Copy link
Contributor

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@TrevorBergeron TrevorBergeron requested review from a team as code owners September 5, 2024 23:33
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. labels Sep 5, 2024
@arwas11 arwas11 removed their assignment Sep 9, 2024
def relational_join(
self,
other: ArrayValue,
join_def: join_def.JoinDefinition,
) -> ArrayValue:
conditions: typing.Tuple[typing.Tuple[str, str], ...] = (),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wikipedia calls these predicates, or more specifically "join predicates". That said, I do see Google SQL calls these join conditions.

Note: we will eventually want to support more than just equality, such as geospatial join predicates (https://carto.com/blog/guide-to-spatial-joins-and-predicates-with-sql), so Tuple doesn't seem like the right type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wikipedia uses the term "condition" plenty as well - seems to be an accepted term. As for spatial predicates - can we leave those for later? Not sure how yet how I would want to represent those. I'm sure we will have one or two more refactors by then as we move towards offset-based indexing.

)
return ArrayValue(join_node)
l_size = len(self.node.schema)
l_mapping = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious what the purpose of these mappings is? Could you give more explanation in a docstring, please?

A guess: is it so we don't actually have to explicitly rename the columns in the SQL compilation step? If so, would it be better to switch to some offset-based logic now instead of mapping strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Callers used to provide the input_id->output_id mapping themselves through the join_def. I'm slowly taking power away from callers to provide the internal ids, so instead of accepting mappings from caller, this method now provides them to callers. I do want to eventually move to entirely offset-based column addressing, but its a multi-step process.

passthrough_columns=[*self.index_columns, offset_col],
)
index_aggregations = [
(ex.UnaryAggregation(agg_ops.AnyValueOp(), ex.free_var(col_id)), col_id)
for col_id in [*self.index_columns]
for col_id in passthrough_cols[:-1]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why every column except the last one? Could you have a comment here explaining, please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment. These correspond to the passthrough_columns argument in unpivot.

@@ -1604,7 +1596,7 @@ def promote_offsets(self, label: Label = None) -> typing.Tuple[Block, str]:
Block(
expr,
index_columns=self.index_columns,
column_labels=self.column_labels.insert(0, label),
column_labels=self.column_labels.insert(len(self.column_labels), label),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it going to be a problem that the label moves from the start to the end?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

caused a few issues - but all resolved now. I want nodes to add variables to the end as it preserves the offsets of the existing variables - this will make some planned bfet transformations simpler.

@TrevorBergeron TrevorBergeron merged commit 3a4a9de into main Sep 11, 2024
22 of 23 checks passed
@TrevorBergeron TrevorBergeron deleted the simplify_join branch September 11, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-dataframes API. size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants