You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "xinrong-meng (via GitHub)" <gi...@apache.org> on 2025/07/23 00:58:18 UTC
[PR] [WIP] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode [spark]
xinrong-meng opened a new pull request, #51627:
URL: https://github.com/apache/spark/pull/51627
### What changes were proposed in this pull request?
Avoid CAST_INVALID_INPUT of "astype" in ANSI mode
### Why are the changes needed?
### Does this PR introduce _any_ user-facing change?
### How was this patch tested?
### Was this patch authored or co-authored using generative AI tooling?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-52922][PS] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on PR #51627:
URL: https://github.com/apache/spark/pull/51627#issuecomment-3115082771
@ueshin may I get a review please?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-52922][PS] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on PR #51627:
URL: https://github.com/apache/spark/pull/51627#issuecomment-3137947841
Thank you @ueshin !
The error is thrown inside the JVM executor as SparkNumberFormatException for now
```py
org.apache.spark.SparkNumberFormatException: [CAST_INVALID_INPUT] The value 'abc' of the type "STRING" cannot be cast to "BIGINT" because it is malformed. Correct the value as per the syntax, or change its target type. Use `try_cast` to tolerate malformed input and return NULL instead. SQLSTATE: 22018
```
We might want to propagate the exception to Python driver as a follow up for error improvement.
I will close the PR for now.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-52922][PS] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #51627:
URL: https://github.com/apache/spark/pull/51627#issuecomment-3137464327
I guess we can leave it as is, raising the error, as pandas also raises an error, although the error type is different.
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-52922][PS] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on PR #51627:
URL: https://github.com/apache/spark/pull/51627#issuecomment-3130069560
Hi @ueshin as for `astype`, it reaches parity with non-ansi, as shown below:
```
>>> spark.conf.set("spark.sql.ansi.enabled", True)
>>> ps.Series(["abc"]).astype(int)
0 NaN
dtype: float64
>>> spark.conf.set("spark.sql.ansi.enabled", False)
>>> ps.Series(["abc"]).astype(int)
0 NaN
dtype: float64
```
To mimic pandas, we check whether values of the string column all represent valid integers or decimals, for example
```py
numeric_regex = r"^\s*-?\d+(\.\d+)?\s*$"
col.rlike(numeric_regex)).count() == 0
```
but that is costly, and may not cover all corner cases.
WDYT?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-52922][PS] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode [spark]
Posted by "ueshin (via GitHub)" <gi...@apache.org>.
ueshin commented on PR #51627:
URL: https://github.com/apache/spark/pull/51627#issuecomment-3120843320
I'm wondering which we should follow here, pandas or non-ansi:
```py
>>> pd.Series(["abc"]).astype(int)
Traceback (most recent call last):
...
ValueError: invalid literal for int() with base 10: 'abc'
```
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-52922][PS] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng closed pull request #51627: [SPARK-52922][PS] Avoid CAST_INVALID_INPUT of "astype" in ANSI mode
URL: https://github.com/apache/spark/pull/51627
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org