AlejandroMorgante opened a new pull request, #60215:
URL: https://github.com/apache/spark/pull/60215

   ### What changes were proposed in this pull request?
   `awaitTermination`/`awaitAnyTermination` (classic 
`StreamingQuery`/`StreamingQueryManager`
   and their Spark Connect equivalents) validate their `timeout` argument with 
a single
   condition: `not isinstance(timeout, (int, float)) or timeout <= 0` (or `< 0` 
for
   `StreamingQueryManager.awaitAnyTermination`), and raise `VALUE_NOT_POSITIVE` 
either way.
   This PR splits the type check into its own `NOT_EXPECTED_TYPE` error, raised 
before the
   positivity check, so a wrongly typed `timeout` is reported as a type error 
instead of a
   value error.
   
   ### Why are the changes needed?
   A wrongly typed `timeout` that looks positive, e.g. the string `'10'` or a 
`Decimal('10')`,
   currently gets folded into the same `VALUE_NOT_POSITIVE` branch as an actual 
negative
   number, producing a misleading message: `"Value for 'timeout' must be 
positive, got
   '10'."` -- but `10` *is* positive; the real problem is that it isn't an 
`int`/`float`.
   `GroupState.setTimeoutDuration`/`setTimeoutTimestamp` already separate these 
two checks and
   are not affected.
   
   This was flagged by an automated review on #60193 (a sibling PR that fixes a 
related but
   distinct bug: `VALUE_NOT_POSITIVE` reporting the argument's type name 
instead of its value
   for genuinely non-positive numbers). That issue is pre-existing and not 
introduced by this
   PR or #60193; it's addressed here as a separate, independently reviewable 
fix.
   
   ### Does this PR introduce _any_ user-facing change?
   Yes, an error message correction for an edge case. Before (e.g.
   `query.awaitTermination("10")`):
   ```
   [VALUE_NOT_POSITIVE] Value for `timeout` must be positive, got 'str'.
   ```
   After:
   ```
   [NOT_EXPECTED_TYPE] Argument `timeout` should be int or float, got str.
   ```
   Negative or zero numeric timeouts are unaffected and still raise 
`VALUE_NOT_POSITIVE` as
   before.
   
   ### How was this patch tested?
   Added `pyspark.sql.tests.streaming.test_streaming_query_validation
   .StreamingQueryTimeoutValidationTests` (4 tests, covering classic and 
Connect, the Connect
   ones guarded by `should_test_connect`), which pass a string timeout and 
assert the new
   `NOT_EXPECTED_TYPE` error via `checkError`. None of these require a 
`SparkSession`, since
   every fixed call site raises before touching its JVM/Connect handle. Also 
manually verified
   that an actual negative/zero timeout still raises `VALUE_NOT_POSITIVE` 
unchanged. Verified
   locally with `python -m unittest` and `ruff check`; the full 
`python/run-tests` / CI suite
   will run on this PR.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   Yes. Generated-by: Claude Code (Claude Sonnet 5)
   
   ---
   This contribution is my original work and I license the work to the project 
under the
   project's open source license.
   
   (First-time contributors here, still learning the contribution flow — happy 
to adjust
   anything that's off.)
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to