LunaLi3781 opened a new pull request, #60225: URL: https://github.com/apache/spark/pull/60225
### What changes were proposed in this pull request? Quote and escape literal top-level column names when `assertDataFrameEqual` reorders columns for `ignoreColumnOrder=True`. Add regression coverage for dots, embedded backticks and a literal `*`, plus a dotted top-level column coexisting with a struct field of the same path. Both equal and unequal inputs are checked. This draft is awaiting a JIRA issue and full source-build validation. ### Why are the changes needed? The existing `select(*sorted(df.columns))` treats column names as expressions. Dots resolve nested fields, a backtick can cause a parsing error, and `*` expands columns. This can reject equal DataFrames and, more importantly, silently accept unequal ones: ```python from pyspark.sql import Row from pyspark.testing import assertDataFrameEqual actual = spark.createDataFrame([(Row(b=1), 2)], ["a", "a.b"]) expected = spark.createDataFrame([(3, Row(b=1))], ["a.b", "a"]) assertDataFrameEqual(actual, expected, ignoreColumnOrder=True) ``` Before this change, both projections read `a.b` from the struct and ignore the differing literal top-level field, so the assertion incorrectly succeeds. After this change, it raises `PySparkAssertionError` as expected. ### Does this PR introduce _any_ user-facing change? Yes. With `ignoreColumnOrder=True`, legal top-level names containing dots, backticks or `*` are treated as literal names. Equal DataFrames with reordered columns pass, while different values in dotted top-level columns are no longer masked by nested-field resolution. Other comparison options are unchanged. ### How was this patch tested? - Added two test methods to `UtilsTestsMixin`, also inherited by Connect parity tests. - Supplemental runtime validation: executed those exact test method bodies plus the existing `test_dataframe_ignore_column_order` method against the checked-out `pyspark/testing/utils.py`, using PySpark 4.0.1's JVM/runtime, Python 3.9.6 and Java 17. Before the change: 3 methods ran, with 2 assertion failures and 2 subtest errors. After the change: all 3 passed. - This supplemental check is not a full master-source build or a Connect parity run. Fork CI will be reported separately; no full-suite pass is claimed yet. - `ruff==0.14.8 check --config pyproject.toml` on both changed files: passed. - `ruff==0.14.8 format --check --config pyproject.toml` on both changed files: passed. - `git diff --check`: passed. Related open PRs for nonfinite values, Row lengths, schema leaf parameters and unordered float matching were checked; this patch is limited to literal column-name projection. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: OpenAI Codex (GPT-6) AI assistance was used for investigation, implementation, regression tests and this description. -- 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]
