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

   ### What changes were proposed in this pull request?
   
   A follow-up of #790 (SPARK-61880), which made the drop-in raise argument 
errors where PySpark raises them, when the plan is built. A round-2 review 
found the remaining places, and the order of MERGE's assignments. Each was 
probed on both clients against a Spark 4.3.0 server.
   
   **Values set at plan build, as PySpark sets them.**
   - **`zipWithIndex(name)`.** PySpark makes it `select(F.col("*"), 
distributed_sequence_id().alias(name))` (connect/dataframe.py:1258-1261). So:
     - a lone surrogate, `5` or `None` fails at the first request, and `b"a"` 
works;
     - `zipWithIndex` and `toJSON` send PySpark's `col` and `alias` origins, 
which the drop-in did not send.
   - **The stateful group methods.** `applyInPandasWithState(outputMode, 
timeoutConf)` and the transformWithState methods set their modes at plan build, 
in PySpark's order of the build (plan.py:2965-2966, 3014 and 3026-3027).
     - `transformWithState` sends its output schema as given, unparsed, where 
it sent it parsed.
     - Both transformWithState methods send `event_time_column_name` (`""` when 
omitted), which they dropped.
   - **The avro and protobuf functions** take their schema, message name and 
descriptor as PySpark's do, as `lit()`s (connect/avro/functions.py, 
connect/protobuf/functions.py). So a str descriptor, or a `messageName` of 
another type, is the server's error, as in PySpark.
   - **`mapInPandas` and `mapInArrow`.** They set their barrier flag at plan 
build, with protobuf's semantics, so `barrier=1` works and `barrier="x"` fails 
at the collect, the cached schema still given. They read `profile.id` at plan 
build too (plan.py:2857-2859), so the profile is created at the first action, 
not at the call.
     - The core's `LogicalPlan::MapPartitions` gets a doc-hidden 
`profile_id_reader`.
   
   **PySpark's errors, and what PySpark takes.**
   - **`nearestByJoin`** checks its mode, direction and join type with 
`.lower()` and `.replace`, as PySpark's plan does (plan.py:1375-1407), so its 
errors name the value as given.
   - **`readStream.name`** checks with Python's `re.match`. So a name ending in 
`\n` is accepted and the server refuses it, and a lone surrogate is 
`INVALID_STREAMING_SOURCE_NAME`, as in PySpark.
   - **`Column.__getattr__` and `SparkSession.__getattr__`** take the str as 
given, so `hasattr` of a lone surrogate is PySpark's.
   - **The connect `Builder.master`** takes any value and does nothing 
(connect/session.py:155-156).
   - **The registrations and interrupts** take their names as protobuf takes 
them: `registerJavaFunction(b"x", ...)`, `udtf.register(b"a", ...)` and 
`interruptTag(b"x")` work. `udf.register(None, f)` registers `fun_<uuid>`, as 
PySpark's does.
   - **`cogroup(5)`** raises the `AttributeError` of `_df`.
   
   **MERGE.**
   - `mergeInto` and its `when*` methods keep their conditions as given. Their 
actions build their assignments as PySpark's do (merge.py:34-55, 77 and 
102-118), with PySpark's errors at the action.
   - The assignments were sent, and their errors raised, in the random order of 
a `HashMap`. They are now sent in the order of their dict, as PySpark's `for k, 
v in assignments.items()` sends them. For example, `insert({"nope1": ..., 
"nope4": ...})` raised the `UNRESOLVED_COLUMN` of any of them at random, and 
now of `nope1`, as PySpark.
   - The core stores the assignments in order. `update` and `insert` take `impl 
IntoIterator<Item = (K, Column)>`, so a `HashMap` still compiles.
   
   **Others.**
   - An `UNSUPPORTED_OPERATION` message, such as `df.to("a\ud800")`'s, keeps a 
lone surrogate as given.
   - `spark.client`'s copies and pickles raise PySpark's `cannot pickle 
'_thread._local' object`.
   - `StorageLevel` pickles at protocols 0 and 1, as PySpark's plain class does.
   - A StructField of metadata of a lone surrogate raises the str's 
`UnicodeEncodeError`, where it raised a JSON error.
   
   `docs/compatibility.md`, `dev/parity/known-differences.md` and 
`dev/design/architecture.md` describe these.
   
   ### Why are the changes needed?
   
   So that these arguments fail where and as PySpark's fail, and take what 
PySpark takes, and so that MERGE sends the same request each time, as PySpark's 
does.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, as above. In the Rust API:
   - `GroupedData::transform_with_state` takes an `output_schema` argument;
   - `MergeIntoWriter`'s `update` and `insert` take an iterator of pairs;
   - `MapPartitions` gets the doc-hidden `profile_id_reader`.
   
   Remaining differences, documented:
   - **A StructField of a lone-surrogate name or metadata** fails when it is 
made, where PySpark makes it and fails later. Matching it would need the core's 
types to hold strs that UTF-8 cannot encode.
   - **`udf.register` and `udtf.register`** parse the DDL and pickle the 
function before they convert the name, where PySpark converts the name first. 
They differ only when the name and the function or the DDL are both bad.
   
   ### How was this patch tested?
   
   - **New tests in `test_dropin_offline.py`.** Each fails on master.
     - The origins of `zipWithIndex` and `toJSON`.
     - The modes of the stateful group methods at plan build.
     - The avro and protobuf functions' literals.
     - The barrier flag and the profile of the map functions.
     - The merge builders' conditions and clauses.
     - `Builder.master`.
     - The names of the registrations and interrupts.
     - The StructFields of lone surrogates.
   
     Extended tests cover `nearestByJoin`, the stream reader's name, the 
attributes, `cogroup`, `to`, the casts, StorageLevel at every protocol, and 
`spark.client`. In Rust: `merge_assignments_are_sent_in_their_order`, 
`map_partitions_reads_the_id_of_its_profile_reader_when_it_is_built`, and the 
core's `transform_with_state` unit test.
   - **The reviewer's probes** match PySpark, apart from the documented 
differences. That includes:
     - the merge order, 3 of 3 runs on both clients;
     - transformWithState's request;
     - the profile created at the first collect;
     - `toJSON`'s query context from the server.
   - **Python.**
     - The offline suite of `coverage.yml` on pandas 2 and 3 (6123 and 6117 
passed).
     - After the rebase on master, `test_dropin_offline.py` and 
`test_dropin_udf_args_offline.py` on pandas 3 (2392 passed).
     - Live `test_dropin_e2e.py` (301 passed).
   - **Rust.**
     - `cargo test -p apache-spark-connect -p apache-spark-connect-core 
--release` (1618 passed);
     - `--features wasm-udf` (1328 passed);
     - after the rebase, `cargo test -p apache-spark-connect --release` (1325 
passed);
     - live `e2e_coverage`, `coverage_plan_map_udtf`, `e2e_dataframe` and 
`e2e_new_methods`.
   - **Lint.** `cargo fmt --all --check`, `cargo +1.100.0 clippy -D warnings`, 
ruff 0.14.0, `audit_no_stubs.sh` and `scripts/tests`.
   
   ### 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