Skip to content

Conversation

@jsjasonseba
Copy link
Collaborator

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.

@jsjasonseba
Copy link
Collaborator Author

Hi @wangxiaoying, I have fixed the tests and applied formatting. Apologies for missing them earlier. Could you please rerun the workflow?

@wangxiaoying
Copy link
Contributor

Thank you @jsjasonseba for the PR! I will take a deeper look at it by this weekend.

Copy link
Contributor

@wangxiaoying wangxiaoying left a 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]>) {}
Copy link
Contributor

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?

Copy link
Collaborator Author

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 {
Copy link
Contributor

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?

dst: &'w mut D,
queries: &[Q],
origin_query: Option<String>,
pre_execution_queries: Option<&[String]>,
Copy link
Contributor

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:

  1. let dispatcher = Dispatcher::new(...); -- remain the same
  2. dispatcher.set_pre_execution_queries(...); --- optional, only set when needed
  3. dispatcher.run() -- remain the same

I think it could be a way to avoid the breaking change. What do you think?

Copy link
Collaborator Author

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.

@jsjasonseba
Copy link
Collaborator Author

Hi @wangxiaoying, I have finished implementing your comments. Feel free to check it at your convenience.

@wangxiaoying wangxiaoying merged commit 6f3e023 into sfu-db:main Feb 2, 2025
2 checks passed
@wangxiaoying
Copy link
Contributor

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!

@jsjasonseba
Copy link
Collaborator Author

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.

@wangxiaoying
Copy link
Contributor

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.

@jsjasonseba
Copy link
Collaborator Author

I think stable release in mid February is fine. Thanks

@wangxiaoying
Copy link
Contributor

Hi @jsjasonseba , v0.4.2 has just released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants