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 SourceScanOptimizer generating duplicated columns #1494

Merged
merged 9 commits into from
Nov 5, 2024

Conversation

serramatutu
Copy link
Contributor

Summary

This PR fixes the issue with SourceScanOptimizer generating duplicated columns. The problem was happening because we didn't check for the same alias referring to different things before merging nodes.

The fix for it was pretty simple, and I added a few tests to catch this issue.

I recommend reviewing commit by commit :)

This commit adds a check to `can_combine`, which is called by the
`SourceScanOptimizer` when determining whether it can combine two
branches into one.

The new check makes sure we only combine branches if:
- both branches don't share aliases
- if they do share aliases, the aliases refer to different things
This commit adds dataflow and SQL snapshot tests that verify we're not
generating duplicated aliases when combining branches.

I created 3 new dummy metrics for these tests: `derived_sharedalias_1a`,
`derived_sharedalias_1b` and `derived_sharedalias_2`. The `1a` and `1b`
variant both make `shared_alias` refer to `bookings`, while the `2`
variant makes it refer to `instant_bookings`. This way we can test the 2
cases:
- If the alias refers to the same thing (`1a` vs `1b`), we can merge
branches safely
- If the alias refers to different things (`1a` vs `2`), we cannot merge
branches safely
Copy link

Thank you for your pull request! We could not find a changelog entry for this change. For details on how to document a change, see the contributing guide.

This commit adds a new integration test that uses
`derived_sharedalias_1a` and `derived_sharedalias_2`.

I manually optimized the SQL from the output of the optimized SQL
snapshot.
@courtneyholcomb courtneyholcomb added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Oct 30, 2024
@github-actions github-actions bot removed the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Oct 30, 2024
@serramatutu
Copy link
Contributor Author

serramatutu commented Nov 4, 2024

Since the last review I added some fixup commits to fix the PR comments.

@serramatutu serramatutu added the Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment label Nov 4, 2024
Copy link
Contributor

@courtneyholcomb courtneyholcomb left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!! 🚢

@serramatutu serramatutu merged commit 44ba096 into main Nov 5, 2024
15 checks passed
@serramatutu serramatutu deleted the serramatutu/validation-fix branch November 5, 2024 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:yes Run Tests With Other SQL Engines Runs the test suite against the SQL engines in our target environment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants