Repository navigation
[SPARK-61154][CONNECT][PYTHON] Raise VALUE_NOT_BETWEEN for a literal of an int beyond the range of a long, in the Python client as PySpark does - #343
Closed
HyukjinKwon wants to merge 1 commit into
Conversation
…of an int beyond the range of a long, in the Python client as PySpark does A Python int beyond the int64 range is no longer converted to a double when it becomes a literal. It raises PySparkValueError VALUE_NOT_BETWEEN as PySpark's LiteralExpression does, with the same message parameters, including PySpark's maximum (JVM_SHORT_MAX). fillna raises the ValueError that PySpark's proto raises for such a value. Co-authored-by: Isaac <no-reply@databricks.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
SPARK-61154: Raise VALUE_NOT_BETWEEN for a literal of an int beyond the range of a long, in the Python client as PySpark does.
lit, the Column operators and comparisons,isin,between,when/otherwise,array, list literals andpivotvalues. The error isPySparkValueErrorVALUE_NOT_BETWEENwitharg_name"value",min"-9223372036854775808" andmax"32767", asLiteralExpression._infer_typeraises it (its maximum isJVM_SHORT_MAX, which PySpark writes this way).fillnaandna.fillwith such an int raiseValueError: Value out of range: <n>, as PySpark's proto raises for an out-of-range long.createDataFrameandspark.sql(..., kwargs)keep their results, which already matched PySpark.Official PySpark 4.3.0 for the same expressions (checked against the same server):
df.where(F.col("a") == 2**63),F.lit(2**70),F.col("a") > 2**70,isin,between,when,array,pivotraisePySparkValueError VALUE_NOT_BETWEEN;fillna(2**70)raisesValueError Value out of range: 1180591620717411303424.Why are the changes needed?
A Python int beyond the int64 range was silently converted to a double. The comparison
df.where(F.col("a") == 2**63)returned the rows with a = 9223372036854775807 and a = 9223372036854775806, because the double rounds, andF.col("a") > 2**70returned no rows. PySpark raises for these values.Does this PR introduce any user-facing change?
Yes. An int beyond the range of a long raises
PySparkValueErrorVALUE_NOT_BETWEENwhere it used to become a double, andfillnaraisesValueErrorfor it.How was this patch tested?
test_int_literals_beyond_a_long_raise_value_not_between_as_pyspark(offline, no server):lit,==,>,isin,between,when,arrayand list literals raiseVALUE_NOT_BETWEENwith the message parameters of PySpark;fillna(2**70)raises theValueError; the bounds of a long and a float beyond them are accepted. The same cases give the same results with official PySpark 4.3.0.wasm-udf, and the offline Python suites (2202 passed, 8 skipped), and the live tests of literals, isin, between, fillna, when and pivot (51 passed) against a local Spark 4.3.0 server; rustfmt passes, and clippy reports no diagnostics in the changed lines.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.