Skip to content

Query cancellation with CTRL-C for R client#3747

Merged
hannes merged 1 commit intoduckdb:masterfrom
hannes:rpending
May 31, 2022
Merged

Query cancellation with CTRL-C for R client#3747
hannes merged 1 commit intoduckdb:masterfrom
hannes:rpending

Conversation

@hannes
Copy link
Member

@hannes hannes commented May 31, 2022

Even though DuckDB is very fast, sometimes a query does run for a long time and sometimes the user does not wish to wait for its completion. With this change, we use the pending query API #2797 to call R_CheckUserInterrupt every now and then. If an interrupt has occurred, query execution will abort. For example,

dbGetQuery(con, "select count(*) from range(1000000), range(1000000) r2")

can now just be aborted by pressing CTRL-C

@hannes
Copy link
Member Author

hannes commented May 31, 2022

CC @krlmlr

Copy link
Contributor

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

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

What are the semantics of pending_query->ExecuteTask() ?

@Mytherin
Copy link
Collaborator

Mytherin commented May 31, 2022

What are the semantics of pending_query->ExecuteTask() ?

See #2797

//! Executes a single task within the query, returning whether or not the query is ready.
//! If this returns RESULT_READY, the Execute function can be called to obtain a pointer to the result.
//! If this returns RESULT_NOT_READY, the ExecuteTask function should be called again.
//! If this returns EXECUTION_ERROR, an error occurred during execution.
//! The error message can be obtained by calling GetError() on the PendingQueryResult.
PendingExecutionResult ExecuteTask();

@SartorialOffense
Copy link

SartorialOffense commented May 31, 2022

Are there plans to bring this to the C API? I hate to be greedy, but I have wished for such a thing for interactive UI's that allow the users to get themselves into trouble with sliders and such. I suspect my C skills are not going to pass muster for a PR. Would you expect the signatures to be something like this:

duckdb_state duckdb_query_pending_init(duckdb_connection connection, const char *query, duckdb_pending_query *out) {
}

duckdb_state duckdb_query_pending_execute(duckdb_pending_query *pending, duckdb_result *out) {
}

duckdb_state duckdb_query_pending_cancel(duckdb_pending_query *pending) {
}

@hannes hannes merged commit 0648470 into duckdb:master May 31, 2022
@hannes hannes deleted the rpending branch May 31, 2022 18:23
@hannes hannes changed the title Query cancellation with CTRL-C to R client Query cancellation with CTRL-C for R client Jun 1, 2022
@Mytherin
Copy link
Collaborator

Mytherin commented Jun 1, 2022

Are there plans to bring this to the C API? I hate to be greedy, but I have wished for such a thing for interactive UI's that allow the users to get themselves into trouble with sliders and such. I suspect my C skills are not going to pass muster for a PR. Would you expect the signatures to be something like this:

duckdb_state duckdb_query_pending_init(duckdb_connection connection, const char *query, duckdb_pending_query *out) {
}

duckdb_state duckdb_query_pending_execute(duckdb_pending_query *pending, duckdb_result *out) {
}

duckdb_state duckdb_query_pending_cancel(duckdb_pending_query *pending) {
}

I agree this would be a useful extension to the C API - I can have a go at adding this.

@SartorialOffense
Copy link

That would be fantastic!

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.

4 participants