-
Notifications
You must be signed in to change notification settings - Fork 609
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
refactor(sql): remove temporary table creation when using inline sql #8149
refactor(sql): remove temporary table creation when using inline sql #8149
Conversation
bbfee93
to
6041191
Compare
@ssanderson I was finally able to clean this up ... years later 😂 |
@@ -157,7 +157,9 @@ def extract_ctes(node): | |||
|
|||
g = Graph.from_bfs(node, filter=(ops.Relation, ops.Subquery, ops.JoinLink)) | |||
for node, dependents in g.invert().items(): | |||
if len(dependents) > 1 and isinstance(node, cte_types): | |||
if isinstance(node, ops.View) or ( |
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 avoid having this special case here? IIC it is only to force turning a View
into a CTE.
Without this the generated SQL would be a subselect, right?
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.
Without this change a cte won't be created, and View must compile to a cte so it's visible by any subsequent query.
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.
Consider the case of joining two aliased ibis expressions. The aliases need to be visible at the top level for a subsequent join that uses them. An aliased subselect would hide all aliases except the immediate parent. AFAIK only CTEs allow defining multiple named relations with the same scope.
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 code still confuses me, you add View
here to the list of the relations which should be wrapped with a CTE, but you exclude the same type from the dict comprehension below.
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'm adding it to the list to be able to generate CTEs later, the ibis CTE
object is only used in a call to replace
, the dict of which filters out the View
objects. There's are a few separate components of that process, that are independent of this PR:
- The extraction of things that should become CTEs
- The replacement of existing nodes with those CTEs
- The construction of sqlglot CTEs based on step 1
I am reusing steps 1 and 3 for this PR, but operating on View
s.
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.
So basically we want to append the ops.View
objects to the list of CTEs. That should be done by ctest + node.find(ops.View)
instead, and outside of this function but rather at the compiler.
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.
The list needs to be assembled in topological order, we can't assemble the View CTEs separately from the others.
953de2b
to
6087e97
Compare
de35024
to
24effc3
Compare
24effc3
to
b7c8e87
Compare
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
…bis-project#8149) This PR fixes a long-standing annoyance with our `.sql` methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various `.sql` methods replace this hack with much more vanilla CTEs. --------- Co-authored-by: Krisztián Szűcs <szucs.krisztian@gmail.com>
This PR fixes a long-standing annoyance with our
.sql
methods. Previously we pooped a bunch of temporary tables or views (depending on the backend), but after this PR the various.sql
methods replace this hack with much more vanilla CTEs.