HyukjinKwon opened a new pull request, #171:
URL: https://github.com/apache/spark-connect-rust/pull/171

   ### What changes were proposed in this pull request?
   
   A follow-up of #167 
([SPARK-60908](https://issues.apache.org/jira/browse/SPARK-60908)), which a 
review of the last commits found two problems in:
   
   - **NumPy scalars:** with a schema, `createDataFrame` now takes NumPy 
scalars as PyArrow does, as the Python value that each stands for:
     - an integer or a float for an integer type, the float truncated;
     - a NumPy bool for a boolean or an integer type;
     - an integer or a float for a floating type.
   - **Integers for floating types:** as PyArrow does, an integer that a 
floating type cannot hold exactly now raises: beyond 2^53 for `double`, and 
2^24 for `float`.
   - **Error messages:** they name the type with its module, as PyArrow's do, 
such as `numpy.int64` or `decimal.Decimal`.
   - **Nesting:** inference stops at 64 levels with `RecursionError`, as 
PySpark's recursion does.
   
   ### Why are the changes needed?
   
   - `createDataFrame([(np.int64(1), np.float32(0.5), np.bool_(True))], "a 
bigint, b double, c boolean")` raised `ValueError: Could not convert 
np.int64(1) ...`, where PySpark returns the row. The conversion before #167 
took them, so this was a regression. Rows from NumPy arrays, such as 
`list(zip(a, b))`, are of these values.
   - `createDataFrame([(2**53 + 1,)], "a double")` silently stored 
`9007199254740992.0`.
   - A value that refers to itself, such as an object whose attribute is the 
object or a list that contains itself, recursed in Rust until the native stack 
overflowed and the interpreter crashed, where PySpark raises `RecursionError`.
   
   Inference cannot rely on Python's recursion limit for that: its frames are 
Rust frames, which the limit does not count. A level takes about 5 KiB of 
stack, so the 64 levels fit a thread of 512 KiB. That is also deeper than the 
server can analyze nested types in practice: its analysis of nested map types 
grows about threefold per level, for PySpark too.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. NumPy scalars convert with a schema, an inexact integer for a floating 
type raises, and a value that refers to itself raises `RecursionError`, all as 
in PySpark 4.3.0.
   
   ### How was this patch tested?
   
   - Against a local Spark 4.3.0 server, a probe of fourteen cases gives the 
same results and messages as official PySpark 4.3.0. The cases are:
     - NumPy scalars for integer, floating and boolean types, out of range, 
truncated and NaN;
     - integers at and beyond 2^53 and 2^24;
     - an object and a list that contain themselves.
   
     The error class is `ValueError`, of which PyArrow's `ArrowInvalid` is a 
subclass.
   - Inference of 63 nested levels succeeds on a thread with a 512 KiB stack, 
and from 64 levels it raises `RecursionError` there; it crashed at 100 levels 
before.
   - New offline tests check the NumPy conversions, the errors and the 
`RecursionError`. A new live test checks the values, and it also passes with 
official PySpark 4.3.0.
   - The lib tests and every integration test, e2e included, against the local 
server (643 passed), the build of all tests with `wasm-udf`, the offline Python 
suites (615 passed, 8 live cases skipped), and the live drop-in and Arrow 
suites (58 passed) and live cases (10 passed). 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.
   


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