-
Notifications
You must be signed in to change notification settings - Fork 62
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
Adds planning and evaluation support for CTEs #1738
Conversation
26a8d22
to
2ee7990
Compare
Adds PError for scalar subquery degree violation
2ee7990
to
6e49c3b
Compare
I believe this is the final PR for adding the currently-planned level of CTE support. We should probably update the Changelog. |
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.
Looks good! I just have a couple of questions and non-blocking comments.
WITH | ||
x AS (SELECT VALUE t FROM << 1, 2, 3 >> t), | ||
y AS (SELECT VALUE x FROM x) | ||
SELECT * FROM y; -- y should not be able to be referenced. |
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.
-- y should not be able to be referenced.
y
is fine, no? It's the x
that should not be able to be referenced inside y
?
@@ -242,6 +242,14 @@ internal class PlanTransform(private val flags: Set<PlannerFlag>) { | |||
return operators.aggregate(input, calls, groups) | |||
} | |||
|
|||
override fun visitRelOpWith(node: Rel.Op.With, ctx: PType): Any { |
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 return Any
and not org.partiql.plan.rel.Rel
?
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.
In the end, it doesn't matter. These all get cast to Rels.
Merging this, and going to add the minor updates to the release commit. |
Relevant Issues
Description
With
that lies at the top of anExprQuerySet (Rex)
. When we go to type this sub-tree, we adjust our environment to include the with clause's elements. In an ideal world, we would immediately type on the conversion from the AST to plan, and we wouldn't need this fairly odd logic, but it is what it is (for now).Scope
to contain a list ofWithListElements
. Then, when attempting to resolve variables locally, the scope is able to find theWithListElement
's representation (anExprQuerySet
) and return its value. This essentially replaces references to the CTE variables with their definitions. This is what PostgreSQL does when a CTE is referenced once.Release Plan
v1.1.0
. There are NO API changes. Only feature additions.v1.1.0
, I'd like to gain some clarity on whether the with element's optional column list is expected for planning/evaluation. If this is needed, there are a few changes that we'll need to make.Examples
Below is an example of a CTE embedded within a CTE:
Below is an example of the errors you may encounter:
License Information
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.