-
Notifications
You must be signed in to change notification settings - Fork 478
adapter: firm up prohibited statements in /api/sql #14400
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
Neat! Can you add a |
/api/sql cannot handle many types of ExecuteResponses; however, it only receives statements as input. To make sure we don't accept statements whose responses we can't handle, this commit introduces a method to try to formalize the types of responses each statement can generate.
0e0e3a4
to
668042e
Compare
This approach is blocked on rust-lang/rust-clippy#9037 making it into
|
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 not convinced this is a good direction to solve this problem. It relies on us correctly keeping multiple big lists of enums to be correct in a way that people adding or changing syntax might not know they need to go and poke at. For example, UPDATE in this PR not being told it might return rows someday. If we left UPDATE as is here, then when it was taught to return rows, there would be no test or compile failure. If a dev adds or changes an ExecuteResponse return from some statement execution, it's totally unknown that they need to also update these functions.
An idea (maybe bad): have the simple query function parse statements and have a single match statement that errors if the parsed statement type can't be executed by it. Then the response serializer can call unreachable
for unexpected responses. This concentrates the logic for "can this be run over the web" into a single place directly where it's needed. It's still brittle, but I think less brittle than this approach. It does suffer from the same big class of flaw here, though: if a dev adds or changes the ExecuteResponse produced by a Statement variant, there's no test or compile error that would inform them they also need to change this code. Hmm.
Statement::Prepare(_) => &[ExecuteResponseKind::Prepare], | ||
|
||
Statement::StartTransaction(_) => &[ExecuteResponseKind::StartedTransaction], | ||
Statement::Update(_) => &[ExecuteResponseKind::Updated], |
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 might also return rows someday. Statement::Delete
has these.
A more robust option is:
This would catch anything that fell out of date as long as it ran through some test somewhere. This has the disadvantage of:
@mjibson if this is more amenable to you, lmk, otherwise I'll just close the issue as not something worth completing. |
FWIW, I'm very pro doing something like this to improve the current code. The current situation sketches me out. |
We spoke over slack, and I agree with the above proposal. |
Closing in favor of #14508 |
/api/sql cannot handle many types of ExecuteResponses; however,
it only receives statements as input. To make sure we don't
accept statements whose responses we can't handle, this commit
introduces a method to try to formalize the types of responses
each statement can generate.
Motivation
This PR adds a known-desirable feature. MaterializeInc/database-issues#4025
Checklist
This PR has adequate test coverage / QA involvement has been duly considered.
This PR evolves an existing
$T ⇔ Proto$T
mapping (possibly in a backwards-incompatible way) and therefore is tagged with aT-protobuf
label.This PR includes the following user-facing behavior changes: