Skip to content
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

fix: Avoid aliasing known CTEs #839

Merged
merged 6 commits into from Jul 11, 2023

Conversation

snapiri
Copy link
Contributor

@snapiri snapiri commented Feb 22, 2023

I now also add the Common Table Expression (CTE) names to the known tables, so they will not be re-added (thus cross-joined with self).

The following snippet (from the issue) was used to validate the change:

    from sqlalchemy import create_engine, MetaData, select, func as F, Table, Column, Integer, ARRAY

    metadata = MetaData()

    table = Table(
        "table1",
        metadata,
        Column("foo", Integer),
        Column("bars", ARRAY(Integer))
    )
    engine = create_engine("bigquery://", future=True)

    selectable = sql.select(table.c).select_from(table).cte('cte')
    q = sql.select([selectable.c.foo, sql.func.unnest(selectable.c.bars).column_valued('unnest_bars')]).select_from(selectable)
    print(q.compile(engine))

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)

Related #368

@snapiri snapiri requested a review from a team as a code owner February 22, 2023 10:11
@snapiri snapiri requested review from a team and rosiezou February 22, 2023 10:11
@google-cla
Copy link

google-cla bot commented Feb 22, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. labels Feb 22, 2023
@tswast tswast added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 12, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 12, 2023
@tswast tswast added the owlbot:run Add this label to trigger the Owlbot post processor. label Jun 12, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jun 12, 2023
@tswast tswast requested a review from a team as a code owner July 5, 2023 15:32
@tswast tswast requested review from GaoleMeng and removed request for rosiezou July 5, 2023 15:32
@tswast tswast added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Jul 5, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 5, 2023
@yoshi-kokoro yoshi-kokoro removed kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jul 5, 2023
@tswast
Copy link
Collaborator

tswast commented Jul 7, 2023

Kokoro failure looks like #875

We might need to address that before we can merge.

@@ -261,6 +261,7 @@ def _known_tables(self):
if isinstance(from_, Table):
known_tables.add(from_.name)
elif isinstance(from_, CTE):
known_tables.add(from_.name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any possibility you could add a test that was failing before this change? Or at least provide a code example so that one of the package maintainers could add such a test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@snapiri snapiri Jul 8, 2023

Choose a reason for hiding this comment

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

Test added

@product-auto-label product-auto-label bot added size: s Pull request size is small. and removed size: xs Pull request size is extra small. labels Jul 8, 2023
@parthea parthea added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Jul 10, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 10, 2023
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Jul 10, 2023
@tswast tswast added kokoro:force-run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Jul 11, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Jul 11, 2023
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jul 11, 2023
@tswast tswast merged commit 8a1f694 into googleapis:main Jul 11, 2023
13 of 14 checks passed
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-sqlalchemy API. size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants