-
Notifications
You must be signed in to change notification settings - Fork 201
Add pre_execution_queries parameter to run setup queries before main query on Postgres and MySQL source #729
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
Add pre_execution_queries parameter to run setup queries before main query on Postgres and MySQL source #729
Conversation
…query on Postgres and MySQL source
…o feature/pre-execution-queries
|
Hi @wangxiaoying, I have fixed the tests and applied formatting. Apologies for missing them earlier. Could you please rerun the workflow? |
|
Thank you @jsjasonseba for the PR! I will take a deeper look at it by this weekend. |
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.
Thank you @jsjasonseba for the PR, I think it looks good in general!
I left a few comments in the review. Please let me know if you have any questions!
| self.origin_query = query; | ||
| } | ||
|
|
||
| fn set_pre_execution_queries(&mut self, _pre_execution_queries: Option<&[String]>) {} |
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.
mark with unimplemented for unsupported sources?
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.
Wow that's neat, just learned about this. Will implement them soon.
| let mut conn = self.pool.get()?; | ||
|
|
||
| if let Some(queries) = &self.pre_execution_queries { | ||
| for query in queries { |
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.
rename the inner query (e.g., to pre_query) so that it won't be confused with the outer query variable?
connectorx/src/dispatcher.rs
Outdated
| dst: &'w mut D, | ||
| queries: &[Q], | ||
| origin_query: Option<String>, | ||
| pre_execution_queries: Option<&[String]>, |
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.
Instead of adding a new parameter to the constructor, maybe it is better to add a set_pre_execution_queries function? When using the dispatcher, we can:
- let dispatcher = Dispatcher::new(...); -- remain the same
- dispatcher.set_pre_execution_queries(...); --- optional, only set when needed
- dispatcher.run() -- remain the same
I think it could be a way to avoid the breaking change. What do you think?
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.
Yeah, I think this a better approach. Thanks for the suggestion.
…o feature/pre-execution-queries
…jasonseba/connector-x into feature/pre-execution-queries
|
Hi @wangxiaoying, I have finished implementing your comments. Feel free to check it at your convenience. |
|
Thank you @jsjasonseba ! I have merged the PR. I also invited you as the collaborator of the project. Hope it will be easier for you to contribute in the future! |
|
Hi @wangxiaoying, you're welcome. Will do more contributions when I got the chance. Just wondering, when is the next release for this change? I am planning to support this use case in polars once it is released. |
I'm currently planning to do a stable release in mid February. But let me know if you want me to have an alpha release for this feature first so you can use it for polars immediately. |
|
I think stable release in mid February is fine. Thanks |
|
Hi @jsjasonseba , v0.4.2 has just released. |
This PR attempts to solve: #728
Also related issues: #645 #471 #656 #512
This PR adds pre_execution_queries parameter to run setup queries before main query. SET statements are typically applied on session/connection scope, so the pre-execution queries must be applied to each connection on each partition. This is implemented by running the pre-execution queries using a connection before assigning the connection to SourcePartition. This will allow all queries run by each connection on each partition to have the necessary settings.
Currently implemented in Postgres and MySQL sources.
I am quite new with rust and I noticed this change is quite breaking to the rust API since rust does not support default args. Please let me know if there is a better way to do this.