Replace sheath leaf clauses with SqlQuery-centric logic #3057
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
SheathLeafClauses is buggy and fails for even simple examples like this:
Throws an error during beta reduction (TODO get the error).
We want to replace the logic with a more practical set of transforms that happen on SqlQuery since that is the place where it should mater that clauses cannot be primitive. The ideal place to do this is between SqlQuery and ExpandNestedQuery because at that time every single SqlQuery that has only one primitive-valued SelectValue (in the FlattenSqlQuery.select) must correspond to a type of situation resembling
SELECT primitive FROM (SELECT x.primitive FROM ...) AS primitive
. It makes it easier to turn the whole construct into something friendly to SQL like:SELECT primitive.value FROM (SELECT x.primitive AS value FROM ...) AS primitive
.