-
-
Notifications
You must be signed in to change notification settings - Fork 234
Detect invalid uses of * and window functions in queries. #1710
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
Conversation
These are for semantically invalid queries that should be detected during analysis.
This prevents a dependency cycle.
We need to resolve functions to know whether a * is being used in an aggregate function or not.
The new package |
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.
lgtm, we do use sql/errors.go
pretty heavily if you wanted to group them there. More testing is usually good, even if just to help future refactors. Segmentation/organization of errors into subpackages probably wouldn't hurt. I'd expect the Dolt auto-bump for this to pass, which you should get notified for after merging.
The docstring for transform.Inspect and sql.Inspect requires that the inputs not be nil. If they are, something has gone wrong and we shouldn't be silently ignoring it. Also removed a call to IsDDLNode that was copied over from validateOperands but doesn't seem to server a purpose.
This PR is the GMS side of the fix for dolthub/dolt#5656.
Preventing panics from invalid window functions is easy: replace the panic with returning a new kind of error.
The invalid *s were trickier. I added an additional analysis rule that runs immediately after resolving function names. It checks for any uses of "*" in a subexpression (so, not just "SELECT *") that aren't used inside a COUNT, COUNTDISTINCT, or JSONARRAY function.
It's possible that there's other places where *s are allowed that we need to account for. It's also possible that there may be some other disallowed uses of * that will pass this and still cause a panic.