Skip to content

Conversation

staticlibs
Copy link
Collaborator

@staticlibs staticlibs commented Jun 3, 2025

This change implements Statement#setQueryTimeout() method. It is implemented by scheduling a background task and calling Statement#cancel() when timeout expires.

Timeouted statement has the same behaviour as it would be if cancelled manually - SQLException is thrown and the statement is closed.

Timeout is applied for all execute* calls. For executeBatch() it is applied separately for every single query in a batch.

Testing: new test added.

Fixes: #212

@@ -20,6 +21,8 @@ public class DuckDBDriver implements java.sql.Driver {
static final String DUCKDB_URL_PREFIX = "jdbc:duckdb:";
static final String MEMORY_DB = ":memory:";

static final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1);
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be helpful when the thread name has a meaningful name. We could achieve this by using a ThreadFactory as second argument to set the name a new thread is created.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the review! Good idea, updated the PR to add this.

@staticlibs staticlibs force-pushed the query_timeout branch 4 times, most recently from cbfa8ff to fdd9a47 Compare June 5, 2025 19:58
This change implements `Statement#setQueryTimeout()` method. It is
implemented by scheduling a background task and calling
`Statement#cancel()` when timeout expires.

Timeouted statement has the same behaviour as it would be if cancelled
manually - `SQLException` is thrown and the statement is closed.

Timeout is applied for all `execute*` calls. For `executeBatch()` it is
applied separately for every single query in a batch.

Testing: new test added.

Fixes: duckdb#212
@staticlibs staticlibs merged commit 3ede02b into duckdb:main Jun 5, 2025
10 checks passed
@staticlibs staticlibs deleted the query_timeout branch June 5, 2025 21:27
staticlibs added a commit to staticlibs/duckdb-java that referenced this pull request Jun 6, 2025
This change restores the contents of duckdb#250 that were inadvertently
removed in duckdb#247.
staticlibs added a commit that referenced this pull request Jun 6, 2025
This change restores the contents of #250 that were inadvertently
removed in #247.
staticlibs added a commit to staticlibs/duckdb-java that referenced this pull request Jun 6, 2025
This change restores the contents of duckdb#250 that were inadvertently
removed in duckdb#247.
staticlibs added a commit to staticlibs/duckdb-java that referenced this pull request Jun 15, 2025
This is a backport of the PR duckdb#247 to `v1.3-ossivalis` stable branch.

This change implements `Statement#setQueryTimeout()` method. It is
implemented by scheduling a background task and calling
`Statement#cancel()` when timeout expires.

Timeouted statement has the same behaviour as it would be if cancelled
manually - `SQLException` is thrown and the statement is closed.

Timeout is applied for all `execute*` calls. For `executeBatch()` it is
applied separately for every single query in a batch.

Testing: new test added.

Fixes: duckdb#212
staticlibs added a commit that referenced this pull request Jun 15, 2025
This is a backport of the PR #247 to `v1.3-ossivalis` stable branch.

This change implements `Statement#setQueryTimeout()` method. It is
implemented by scheduling a background task and calling
`Statement#cancel()` when timeout expires.

Timeouted statement has the same behaviour as it would be if cancelled
manually - `SQLException` is thrown and the statement is closed.

Timeout is applied for all `execute*` calls. For `executeBatch()` it is
applied separately for every single query in a batch.

Testing: new test added.

Fixes: #212
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.

[Feature Request] Add support to java.sql.Statement#setQueryTimeout
2 participants