-
-
Notifications
You must be signed in to change notification settings - Fork 259
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 support for post_parse_analyze to PgHooks #800
Add support for post_parse_analyze to PgHooks #800
Conversation
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.
There's a lot of code duplication in this PR to satisfy the cfg
requirements? But it looks almost exactly the same? Why not just #[cfg]
on a single let
binding inside the pgx_post_parse_analyze
function?
I'd like to remove the duplicate code, but am not sure how to do it. I'm still new to rust so please let me know if there's something I can learn here! The function signature is different in pg14 since it takes an extra argument. Is there a way to conditionally compile part of the parameter list in rust? We'd need something equivalent to this C code: void pgx_post_parse_analyze(
ParseState *ps,
Query *query,
#if PG14
JumbleState *jumble_state
#endif /* PG14 */
) { My naive attempt to mark the parameter itself with a cfg attribute doesn't work unsafe extern "C" fn pgx_post_parse_analyze(
parse_state: *mut pg_sys::ParseState,
query: *mut pg_sys::Query,
#[cfg(any(feature = "pg14"))]
jumble_state: *mut JumbleState
) {
Also, I think we'd need 3 cfg blocks to make it work. Something like this: + #[cfg(any(feature = "pg14"))]
+ jumble_state: *mut JumbleState
) {
fn prev(
parse_state: PgBox<pg_sys::ParseState>,
query: PgBox<pg_sys::Query>,
- _jumble_state: Option<PgBox<JumbleState>>,
+ jumble_state: Option<PgBox<JumbleState>>,
) -> HookResult<()> {
HookResult::new(unsafe {
match HOOKS.as_mut().unwrap().prev_post_parse_analyze_hook.as_ref() {
None => (),
+ #[cfg(any(feature = "pg10", feature = "pg11", feature="pg12", feature="pg13"))]
Some(f) => (f)(parse_state.as_ptr(), query.as_ptr()),
+ #[cfg(any(feature = "pg14"))]
+ Some(f) => (f)(parse_state.as_ptr(), query.as_ptr(), jumble_state.unwrap().as_ptr()), |
Ooh, the extra parameter part I didn't notice. |
That might be hard to work around due to #794 but hopefully that will be fixed soon. |
#813 was merged, you might want to take a second crack at this? |
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.
You probably will want to also support PostgreSQL 15.
@workingjubilee @jteplitz #830 has landed in develop |
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!
No description provided.