Skip to content

Conversation

tonyalaribe
Copy link
Contributor

@tonyalaribe tonyalaribe commented Oct 5, 2025

Introduce QueryHook so users can process custom queries with own logic.
This will allow users to implement other behaviors like SET queries,
s other sql query kinds which might not be supported by datafusion-postgres.

The source conversation is from this thread: #201

@tonyalaribe
Copy link
Contributor Author

@sunng87 I made a pr as discussed. I'm unsure what kind of Statement arguement to accept. datafusion::sql::Statement or datafusion::logical_expr::sqlparser::ast::Statement.

datafusion::sql::Statement is a wrapper enum with a variant Statement::Statement(Boxdatafusion::logical_expr::sqlparser::ast::Statement)

@sunng87
Copy link
Member

sunng87 commented Oct 5, 2025

Hello @tonyalaribe , Thank you so much for the quick update! It should be the Statement from parser. I will leave some comments inline.

}

// Call query hook with the parsed statement
if let Some(hook) = &self.query_hook {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loop over query_hooks and make early return if one of them returns non-empty response

statement: &Statement,
session_context: &SessionContext,
client: &dyn ClientInfo,
) -> Option<PgWireResult<Vec<Response>>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the input is a single Statement, the return value should be at most one Response

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I've updated the code to return a single Response.


// Call query hooks with the parsed statement
for hook in &self.query_hooks {
let wrapped_statement = Statement::Statement(Box::new(statement.clone()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need wrap here? Can we feed statement directly to hook.handle_query?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was simply felt we would want to expose the datafusion Statement and types to users instead of the sqlparser's. But not wrapping might also be cleaner. I've updated the code.

Copy link
Member

@sunng87 sunng87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is some minor issue with early return. But overall it looks good to me and let me pick up the work to update. Thank you so much @tonyalaribe ! This is a major step for extensibility of datafusion-postgres.

@sunng87 sunng87 merged commit 2b9a11c into datafusion-contrib:master Oct 7, 2025
6 checks passed
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