Skip to content

Conversation

@birschick-bq
Copy link
Contributor

@birschick-bq birschick-bq commented Sep 11, 2025

Adds implementation of AdbcStatement.Cancel to the BigQuery driver.

  • A CancellationRegistry tracks CancellationContext
  • When Statment.Cancel call is made, it will cancel all the registered CancellationContext.
  • When a JobCancellationContext is registered, it will attempt to cancel the job on the server.

@birschick-bq
Copy link
Contributor Author

@davidhcoe - Please review when you have a chance.

@birschick-bq
Copy link
Contributor Author

birschick-bq commented Sep 11, 2025

@CurtHagenlocher / @davidhcoe

Checking to see if the semantics should be that once a statement is cancelled - it stays cancelled? Or should the Cancel only apply when an execution is active?

Additionally. The docs for Cancel says any streams should also be cancelled. Should I try to implement that behavior, as well?

@CurtHagenlocher
Copy link
Contributor

Checking to see if the semantics should be that once a statement is cancelled - it stays cancelled? Or should the Cancel only apply when an execution is active?

While this may not all be spelled out explicitly, the intent for a statement is clearly that a single statement should only be used to execute one query at a time and that a single statement may be used to execute multiple different queries consecutively. From this perspective, cancellation should only affect the currently-executing query. Cancelling the current query should not prevent the statement from being used to execute a new query.

Additionally. The docs for Cancel says any streams should also be cancelled. Should I try to implement that behavior, as well?

Ideally, yes.

@birschick-bq
Copy link
Contributor Author

Checking to see if the semantics should be that once a statement is cancelled - it stays cancelled? Or should the Cancel only apply when an execution is active?

While this may not all be spelled out explicitly, the intent for a statement is clearly that a single statement should only be used to execute one query at a time and that a single statement may be used to execute multiple different queries consecutively. From this perspective, cancellation should only affect the currently-executing query. Cancelling the current query should not prevent the statement from being used to execute a new query.

Additionally. The docs for Cancel says any streams should also be cancelled. Should I try to implement that behavior, as well?

Ideally, yes.

Okay. That is much more clear.

@birschick-bq birschick-bq marked this pull request as draft September 15, 2025 17:15
@birschick-bq birschick-bq marked this pull request as ready for review October 1, 2025 20:19
private readonly CancellationRegistry cancellationRegistry;
private readonly CancellationTokenSource cancellationTokenSource;

private bool _disposedValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

By usage, this code base has over twice as many _disposeds as _disposedValues (though we could normalize that in a separate PR).

Copy link
Contributor

Choose a reason for hiding this comment

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

(In the same vein, this class has two fields that don't start with an underscore and one which does. And here too is another inconsistency across the code base :(.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry. It is autogenerated code that I should change. I'll create a PR to normalize to _disposed from _disposedValue.

Job = job;
}

public BigQueryJob? Job { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the setter throw an exception if the existing value is non-null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, the ability to swap out a Job mid-context is by design. It allows multiple calls/steps to share the same context.

}
}

public static bool ContainsException<T>(Exception exception, out T? containedException) where T : Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, this could share an implementation with the other overload via e.g.

public static bool ContainsException<T>(Exception exception, out T? containedException) where T: Exception
{
    if (ContainsException(exception, typeof(T), out Exception? found))
    {
        containedException = (T)found;
        return true;
    }

    containedException = default;
    return false;
}

@CurtHagenlocher CurtHagenlocher merged commit 8bc03ef into apache:main Oct 13, 2025
6 checks passed
@birschick-bq birschick-bq deleted the dev/birschick-bq/bigquery-cancel-statement branch October 13, 2025 17:33
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.

3 participants