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

   ### What changes were proposed in this pull request?
   
   [SPARK-61321](https://issues.apache.org/jira/browse/SPARK-61321): Send the 
count of `DataFrame.take` to the server as `limit` does, and pass the receiver 
to `DataFrame.transform` as PySpark does.
   
   - `DataFrame.take(num)` takes `num` as an int, as `head` and `limit` do, and 
runs `limit(num).collect()`, as PySpark's `take` does. The server checks the 
count: `take(-1)` raises `AnalysisException` 
`INVALID_LIMIT_LIKE_EXPRESSION.IS_NEGATIVE`, as PySpark does. Before, the 
drop-in rejected a negative count while converting the argument, with 
`OverflowError: can't convert negative int to unsigned`.
   - `DataFrame.transform(func, *args, **kwargs)` calls `func` with the 
DataFrame it is called on, as PySpark's does, so a subclass of 
`pyspark.sql.connect.dataframe.DataFrame` keeps its methods in the callback and 
`transform(lambda d: d)` returns the subclass instance. Before, the callback 
got a new base-class frame of the same plan.
   
   Checked and unchanged: `cache`, `persist` and `unpersist` already return the 
receiver. `pandas_api`, `foreach` and `foreachPartition` already pass the bound 
receiver. `checkpoint` and `localCheckpoint` return a new base-class frame, as 
PySpark's Connect client does.
   
   ### Why are the changes needed?
   
   - `spark.range(3).take(-1)` raised `OverflowError`, while `head(-1)` and 
`limit(-1)` raised the server's `AnalysisException`, as PySpark does.
   - `MyDF(plan, session).transform(lambda d: d.twice())` raised `'Column' 
object is not callable`, because the callback's argument was a base-class frame 
without `twice`. PySpark passes the `MyDF` instance and the call works.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `take` of a negative count raises the server's `AnalysisException`, and 
`transform` passes the DataFrame it is called on, a subclass instance included. 
Nothing else changes.
   
   ### How was this patch tested?
   
   - Offline test `test_transform_passes_the_receiver_itself_as_pyspark` in 
`python/tests/test_dropin_offline.py` (before 
`test_join_on_lists_join_on_their_conjunction_or_names_as_pyspark`): with a 
subclass of `pyspark.sql.connect.dataframe.DataFrame`, the callback gets the 
receiver itself, `transform(lambda d: d)` returns the subclass instance, and 
`d.twice()` in the callback sends a Project plan. With PySpark 4.3.0 the same 
statements give `MyDF` and the `twice()` rows, `[(0,), (2,), (4,)]`.
   - Offline test 
`test_take_sends_its_count_as_a_limit_for_the_server_to_check` in 
`python/tests/test_dropin_offline.py` (same place): `take(2)` and `take(-1)` 
send `Relation.limit` with the count, as an int32, which the server checks.
   - Live test 
`test_take_of_a_negative_count_raises_the_server_error_as_pyspark` in 
`python/tests/test_dropin_e2e.py` (before 
`test_collected_rows_behave_as_pyspark_rows`): `take(-1)` raises 
`AnalysisException` with the condition 
`INVALID_LIMIT_LIKE_EXPRESSION.IS_NEGATIVE`, and `take(2)` returns two rows. 
PySpark 4.3.0 on the same server gives the same condition.
   - Both offline tests and the live test fail with the previous `take` and 
`transform` (checked by reverting the change temporarily).
   - The build of all tests, the offline Python suites (2929 passed, 8 skipped) 
with the rebuilt extension, the new offline tests also under pytest 9.2, and 
the live drop-in tests `-k "transform or take"` (24 passed) against a local 
Spark 4.3.0 server. Clippy reports no new 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