viirya opened a new pull request, #543: URL: https://github.com/apache/spark-connect-rust/pull/543
### What changes were proposed in this pull request? Two changes in `crates/spark-connect/src/plan.rs` and its callers. - The `AsOfJoin` plan node kept its join type and its direction as strings. They are now `AsOfJoinType` (`Inner`, `LeftOuter`, `Other(String)`) and `AsOfJoinDirection` (`Backward`, `Forward`, `Nearest`, `Other(String)`), each with `parse`, `as_str`, `From<&str>` and `Default`. `AsOfJoinOptions.join_type` and `direction` take them, and the PyO3 `_joinAsOf` parses `how` and `direction` into them. - `PlanIds::node_of`, which returned one node of a plan ID, is now `nodes_of`, which returns every live node of it. `set_observations` sets the Observation from the node that observes. ### Why are the changes needed? **As-of join.** A join type or a direction could be any string in the plan. PySpark's `_joinAsOf` only asserts that `how` is a string. It sends `how` and `direction` as they are, and the server reads more spellings than the names (`JoinType` ignores case and underscores, `AsOfJoinDirection` ignores case) and refuses the rest in the analysis (`UNSUPPORTED_JOIN_TYPE`, `AS_OF_JOIN.UNSUPPORTED_DIRECTION`, or the `require` of `AsOfJoin` for a join type that is not inner or left outer). So the enums name the values that the server joins by, and keep any other string in `Other`, which is sent as it is. No request changes, and the client raises no error that PySpark does not. **Plan IDs.** A plan ID is of more than one node whenever a relation that the session sent has a DataFrame of its own (`DataFrame::from_sent_relation`), such as an unpickled copy of a DataFrame: `assign` gives the copy, a `Raw` node, the plan ID of the DataFrame it was of, which may still be alive. `node_of` scanned a `HashMap` and took the first node of the ID that it met, so either of them. Its one caller, `set_observations`, skipped the metrics when that node was the copy, so the Observation of an observed DataFrame that had such a copy could stay empty. At most one node of an ID is an `Observe`: `assign` is only called for `Raw` nodes, and `id_of` numbers from one process-wide counter that `assign` moves past each ID it gives. The lookup stays a scan. It runs once for each observed metric of a response, so a few times for an execution of a plan with an `observe` and never otherwise, over the nodes that the session tracks. A second map by plan ID would have to be kept in step with the first on every insert and prune. ### Does this PR introduce _any_ user-facing change? Yes. - Rust: `AsOfJoinOptions.join_type` and `direction` are `AsOfJoinType` and `AsOfJoinDirection` in place of `String`. `"left".into()` and `AsOfJoinType::parse` take a string. - An Observation of a DataFrame whose relation has sent copies in the session, such as an unpickled copy, is now always set by the metrics of an execution. - Python: no change in `_joinAsOf`. `how` and `direction` are sent as before. ### How was this patch tested? - New `crates/spark-connect/tests/as_of_join.rs`: the names parse to their variants and are sent by name, and other strings (`"LEFT"`, `"left_outer"`, `"sideways"`, `""`) are kept in `Other` and sent byte for byte, with no client error. - New `plan_id_tests` in `plan.rs`: `nodes_of` for a numbered node, for nodes given the same ID, after a node is dropped, and for an unknown ID. - New `observed_metrics_set_the_observation_of_a_relation_that_has_sent_copies` in `dataframe.rs`, with 16 sent copies of an observed relation. It fails when the lookup takes one node of the ID. - `test_join_as_of_sends_the_as_of_join_as_pyspark` in `python/tests/test_dropin_offline.py` now also sends each of eight `how` values with each of six `direction` values and checks the fields of the request, and checks the `AssertionError` of a `how` that is not a string. - `cargo test -p apache-spark-connect --release --lib` (616 passed), the `--no-run` builds with and without `wasm-udf`, `cargo fmt --all --check`, the golden-proto tests with their golden files unchanged, and the Python offline suite with `TZ=UTC` (1879 passed, 8 skipped). ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Fable 5.2 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]
