spark-test commented on code in PR #60193:
URL: https://github.com/apache/spark/pull/60193#discussion_r4504559779
##########
python/pyspark/sql/streaming/query.py:
##########
@@ -220,7 +220,7 @@ def awaitTermination(self, timeout: Optional[int] = None)
-> Optional[bool]:
if not isinstance(timeout, (int, float)) or timeout <= 0:
raise PySparkValueError(
errorClass="VALUE_NOT_POSITIVE",
- messageParameters={"arg_name": "timeout", "arg_value":
type(timeout).__name__},
+ messageParameters={"arg_name": "timeout", "arg_value":
str(timeout)},
Review Comment:
**Non-blocking (P2):** The `if` condition here also sends any `timeout` that
is not an `int` or `float` into this raise, so `str(timeout)` now reports a
wrongly typed value as if it were a number that failed the sign check. For
example, `q.awaitTermination("10")`, say with a timeout read unconverted from a
config file or an environment variable, now fails with "Value for `timeout`
must be positive, got '10'.", and `Decimal("10")` or a NumPy integer scalar
produces the same message. That message contradicts itself and no longer points
at the type; before this PR these calls reported the type name, such as `'str'`
or `'Decimal'`. The same happens in `awaitAnyTermination` below (line 601) and
in both Spark Connect methods (`python/pyspark/sql/connect/streaming/query.py`,
lines 89 and 224).
Reporting `str(timeout)` only when `timeout` is an `int` or `float`, and
`type(timeout).__name__` otherwise, keeps the fix for rejected numbers and
restores the earlier message for wrongly typed values.
**Verification:**
- **Regression:** For classic and Spark Connect awaitTermination and
awaitAnyTermination, a timeout that is not an int or float, including
positive-looking values such as the string '10' and Decimal('10'), raises
VALUE_NOT_POSITIVE whose arg_value is its type name rather than its value.
- **Behavior:** For the same four methods, an int or float timeout that the
method rejects, such as -5, still reports that value in arg_value.
- **Compatibility:** A non-numeric timeout such as 'hello' still raises a
ValueError from classic and Spark Connect awaitTermination and
awaitAnyTermination, so callers that catch ValueError keep working.
--
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]