Skip to content
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

Enable call to PreparedStatement's cancel #137

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BagusThanatos
Copy link

Metabase calls PreparedStatement's .cancel method in order to stop any queries cancelled by the user as shown here
https://github.com/metabase/metabase/blob/ceacccd0b1aa4dc51c0c88228f91922fe6934ec0/src/metabase/driver/sql_jdbc/execute.clj#L735

We observed that it failed to cancel with java.lang.UnsupportedOperationException which looks like due to cancel function not currently proxied.

Any feedback is appreciated as I'm not familiar with clojure and this is my first interaction with Metabase codebase.

Thank you

@lpoulain
Copy link
Collaborator

lpoulain commented Jan 8, 2025

Would you mind rebasing your PR?

@BagusThanatos
Copy link
Author

Would you mind rebasing your PR?

Sure, no problem.

@BagusThanatos BagusThanatos force-pushed the add-cancel-prepared-statement branch from 3c0e7f4 to 8f4f103 Compare January 9, 2025 05:37
@BagusThanatos
Copy link
Author

@lpoulain Rebase done.

@lpoulain
Copy link
Collaborator

lpoulain commented Jan 9, 2025

@BagusThanatos thanks a lot. Now, I'm trying to reproduce the issue on the latest branch but cannot get the error you describe. I created a question with a text variable (to force the use of prepared statement) and canceled the query but get no error. Are you using a different method?

@BagusThanatos
Copy link
Author

@BagusThanatos thanks a lot. Now, I'm trying to reproduce the issue on the latest branch but cannot get the error you describe. I created a question with a text variable (to force the use of prepared statement) and canceled the query but get no error. Are you using a different method?

@lpoulain For the error to be logged, I had to modify Metabase source code as below, as it only logged statement cancellation failed.
image

Also, if this Optimized Prepared Statement was enabled, adding it here if it matters
image

@lpoulain
Copy link
Collaborator

I ran some tests and it works fine. However, for the sake of completeness, (cancel [] (.cancel stmt)) should also be added to proxy-prepared-statement and sql-jdbc.execute/statement. You can either add them to your PR or I can file my own PR with all three additions.

Signed-off-by: Bagus Nurtomo <bagus.nurtomo@pm.me>
Signed-off-by: Bagus Nurtomo <bagus.nurtomo@pm.me>
@BagusThanatos BagusThanatos force-pushed the add-cancel-prepared-statement branch from 8f4f103 to b49c048 Compare January 16, 2025 06:22
@BagusThanatos
Copy link
Author

I ran some tests and it works fine. However, for the sake of completeness, (cancel [] (.cancel stmt)) should also be added to proxy-prepared-statement and sql-jdbc.execute/statement. You can either add them to your PR or I can file my own PR with all three additions.

I've updated the PR, and would appreciate it if you can confirm whether it's the correct place(s).
Thanks!

@lpoulain lpoulain self-requested a review January 16, 2025 14:11
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