HyukjinKwon opened a new pull request, #839:
URL: https://github.com/apache/spark-connect-rust/pull/839
### What changes were proposed in this pull request?
PySpark's `StreamingQuery.awaitTermination` and
`StreamingQueryManager.awaitAnyTermination` (`connect/streaming/query.py:79-89`
and `:214-224`) do two things:
- they refuse a timeout only when it is not an int or a float, or when
`timeout <= 0`, with `VALUE_NOT_POSITIVE` of the name of its type;
- they then set `int(timeout * 1000)` in the int64 field `timeout_ms` of the
command.
The drop-in's binding took the timeout as a float and refused it unless
`seconds > 0.0` (`positive_timeout`, `crates/pyspark-rs/src/streaming.rs`). The
Rust API's own `await_termination` and `await_any_termination` raise PySpark's
errors since #831 (SPARK-61961), but the binding's check ran first.
Checked on both clients against a Spark 4.3.0 server, with a running query
`q`:
| Call | pyspark-client 4.3.0 | drop-in before |
|---|---|---|
| `q.awaitTermination(float("nan"))`,
`spark.streams.awaitAnyTermination(float("nan"))` | `ValueError: cannot convert
float NaN to integer` | `PySparkValueError: [VALUE_NOT_POSITIVE] ... got
'float'.` |
| `q.awaitTermination(10**400)`, and the same of `awaitAnyTermination` |
`ValueError: Value out of range: 1000...0` (all the digits of `10**403`) |
`OverflowError: int too large to convert to float` |
| `q.awaitTermination(2**53 + 1)` | sends `timeout_ms` 9007199254740993000 |
sends 9007199254740992000, rounded by a float |
The other timeouts already gave PySpark's errors and requests on both
clients: 0, -1, 0.0, -0.5, infinities, 1e300, 9.3e15, True, False, 1e-9 and
`"1"`.
The change:
- **The binding** (`crates/pyspark-rs/src/streaming.rs`) computes the
timeout with Python's own operators, as PySpark does:
- `isinstance(timeout, (int, float))` and `timeout <= 0`, else
`VALUE_NOT_POSITIVE`;
- then `int(timeout * 1000)`, which raises the `ValueError` of a NaN and
the `OverflowError` of an infinity;
- an int beyond a long raises `ValueError: Value out of range: <int>`, as
protobuf's int64 field does.
- **The core** (`crates/spark-connect/src/streaming.rs`) adds the doc-hidden
`StreamingQuery::await_termination_ms` and
`StreamingQueryManager::await_any_termination_ms`. They send the milliseconds
as they are given. The binding calls them. The f64 `await_termination` and
`await_any_termination` of the Rust API are now wrappers of them and are
unchanged.
### Why are the changes needed?
So that the waits of a streaming query raise PySpark's errors of a NaN and
of a large int, and send the timeout of an int as PySpark sends it.
### Does this PR introduce _any_ user-facing change?
Yes, in the drop-in, as in the table above:
- `awaitTermination` and `awaitAnyTermination` of a NaN raise `ValueError`;
- those of an int beyond a float raise protobuf's `ValueError`;
- an int timeout is sent exactly.
The Rust API is unchanged, apart from the two new doc-hidden methods.
### How was this patch tested?
- **Probes of both clients against a Spark 4.3.0 server.** After the change,
`p_await.py` (13 timeouts of both waits, the source names and `changes`) and
`p_await_int.py` (NaN, `10**16`, `10**400`) give identical output.
- **New tests**, each failing without the change:
- `test_streaming_query_waits_compute_the_timeout_as_pyspark` in
`test_dropin_offline.py`, on the mock server. It checks:
- the `ValueError`s of a NaN, of `10**400` and of `10**16`, before any
request;
- the `timeout_ms` that both waits send for `2**53 + 1`, `True` and
`1.5`.
- `await_timeouts_in_milliseconds_are_sent_as_they_are` in the core: the
commands of `Some(9007199254740993000)`, `Some(0)` and `None` for both waits.
- `cargo test -p apache-spark-connect --release --lib`: 789 passed.
- `cargo test -p pyspark-rs --lib`: 13 passed.
- The offline suite of `coverage.yml`: 6328 passed, 77 skipped.
- `test_dropin_e2e.py` against a Spark 4.3.0 server: 318 passed.
- **Lint and guards:**
- `cargo fmt --all --check`;
- `cargo +1.100.0 clippy -p apache-spark-connect-core -p
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p apache-spark-connect
-p apache-spark-connect-core`;
- ruff 0.14.0, `test_ruff_excludes.py`, `scripts/audit_no_stubs.sh`;
- `scripts/gen_type_stubs.py --check` and `scripts/gen_fn_dispatch.py
--check` against the v4.3.0 source;
- `test_type_stubs_offline.py`: 7 passed, 2 skipped;
- the test-list guards of `coverage.yml` and `build_python_connect.yml`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]