HyukjinKwon opened a new pull request, #814:
URL: https://github.com/apache/spark-connect-rust/pull/814
### What changes were proposed in this pull request?
PySpark's `PlanObservedMetrics` (`pyspark/sql/connect/client/core.py`) keeps
the `Expression.Literal` messages that the server sends. Its `pairs` converts
them with `LiteralExpression._to_value` when it is read. The drop-in's kept the
values that the Rust transport had decoded. So its `metrics`, its `repr` and
the `UNKNOWN_RESPONSE` that names it differed. Code reads them in:
- `DataFrame.executionInfo`;
- the `ExecutionInfo` of `SparkSession.client`'s `to_table`, `to_pandas` and
`execute_command` (#779);
- the `attrs` of `to_pandas`.
Checked on both clients against a Spark 4.3.0 server:
| | pyspark-client 4.3.0 | drop-in before |
|---|---|---|
| `client.to_pandas(plan, {"seen":
o})[0].attrs["observed_metrics"][0].metrics` | `[long: 4\n, long: 3\n]`,
`Expression.Literal` messages | `[4, 3]` |
| `repr` of it | `Plan observed(seen=[long: 4\n, long: 3\n])` | `Plan
observed(seen=[4, 3])` |
| `execute_command_as_iterator` of a command of observed metrics |
`UNKNOWN_RESPONSE` naming `Plan observed(w=[long: 3\n])` | `... Plan
observed(w=[3])` |
`pairs`, `flows` and `to_dict` were the same on both.
The change:
- `execution_metrics` (`crates/pyspark-rs/src/dataframe.rs`) gives
`PlanObservedMetrics` the literals as messages of `pyspark.sql.connect.proto`.
- `PlanObservedMetrics` is PySpark's. Its `pairs` and `to_dict` convert the
literals with PySpark's own `LiteralExpression._to_value`, which raises
`UNSUPPORTED_LITERAL` for a literal that it does not convert when they are
read. The transport's `_UnsupportedLiteral` marker did that before.
- The marker stays for the metrics of an Observation, which the action
checks before it converts them.
`docs/compatibility.md` says so in the "SparkSession.client" section.
### Why are the changes needed?
So that the observed metrics of an execution are PySpark's: their messages,
their `repr`, and the errors that name them.
### Does this PR introduce _any_ user-facing change?
Yes. `PlanObservedMetrics.metrics` is a list of `Expression.Literal`
messages, and its `repr` is PySpark's. `pairs`, `flows` and `to_dict` are
unchanged.
### How was this patch tested?
- **Probes of both clients against a Spark 4.3.0 server:**
- `to_pandas`'s `attrs`, `DataFrame.executionInfo` and
`execute_command_as_iterator`'s error give identical output;
- observed arrays, structs, maps, nested structs, timestamps and decimals
give identical `flows`;
- a year-month interval raises the same `UNSUPPORTED_LITERAL` when `flows`
is read.
- **Tests:**
- `test_observed_metrics_expose_their_name_metrics_and_keys_as_pyspark`
constructs `PlanObservedMetrics` of `Expression.Literal` messages, as PySpark's
takes them, and checks their `repr`, `pairs`, `to_dict` and
`UNSUPPORTED_LITERAL`;
- `test_execution_info_and_operation_id` does the same with
`ExecutionInfo`;
-
`test_flows_raise_for_a_metric_that_holds_one_pyspark_cannot_convert_as_pyspark`
and `test_execution_info_decodes_observed_metrics_and_operation_id` build
their mock literals as the server sends them, of their element, key, value and
struct types, which `_to_value` reads.
- `cargo test -p pyspark-rs --lib`: 12 passed.
- The offline suite of `coverage.yml`: 6198 passed, 77 skipped.
- `test_dropin_e2e.py` against a Spark 4.3.0 server: 305 passed.
- **Lint:**
- `cargo fmt --all --check`;
- `cargo +1.100.0 clippy -p apache-spark-connect-core -p
apache-spark-connect -p pyspark-rs --all-targets -- -D warnings`;
- `RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p apache-spark-connect
-p apache-spark-connect-core`;
- ruff 0.14.0, `test_ruff_excludes.py`, `scripts/audit_no_stubs.sh`;
- the guards of `coverage.yml` and `build_python_connect.yml`.
### 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]