LearnFirst opened a new pull request, #59361:
URL: https://github.com/apache/spark/pull/59361

   ### What changes were proposed in this pull request?
   
   This PR adds tests to `SQLTestsMixin` in 
`python/pyspark/sql/tests/test_sql.py` for code paths of `spark.sql()` 
keyword-argument formatting that were not covered. Since the mixin is shared by 
`test_parity_sql.py`, the tests run in both classic and Spark Connect:
   
   - `test_kwargs_string_literal`: string values round-trip unchanged, 
including single and double quotes, backslashes (e.g. `C:\new`, a trailing 
`\`), `\'`, control characters, an injection-like value (`x' OR '1'='1`), and 
braces
   - `test_kwargs_dataframe_referenced_twice`:
     - the same DataFrame referenced twice by one name reuses one view
     - the same DataFrame passed under two names reuses one view
     - different DataFrames get different views
   
   ### Why are the changes needed?
   
   To improve test coverage of 
`pyspark.sql.connect.sql_formatter.SQLStringFormatter`. The string-literal 
branch and the view-reuse branch had no tests, so regressions in 
quoting/escaping or in view naming would not be caught.
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. Test-only change.
   
   ### How was this patch tested?
   
   Added unit tests in `python/pyspark/sql/tests/test_sql.py`, run in classic 
and Spark Connect:
   
   ```
   python/run-tests --python-executables=python --testnames 
"pyspark.sql.tests.test_sql,pyspark.sql.tests.connect.test_parity_sql"
   ```
   
   Ran the Connect parity tests with coverage before and after the change:
   
   ```
   python/run-tests-with-coverage --python-executables=python --testnames 
pyspark.sql.tests.connect.test_parity_sql
   ```
   
   Coverage of `pyspark/sql/connect/sql_formatter.py`:
   
   | | Stmts | Miss | BrPart | Cover |
   |---|---|---|---|---|
   | Before | 34 | 5 | 3 | 78% |
   | After | 34 | 2 | 1 | 93% |
   
   The remaining uncovered lines are the no-op `clear()` and the error for a 
non-plain column reference. The latter raises `PySparkValueError` without an 
error class in Spark Connect, unlike classic 
(`VALUE_NOT_PLAIN_COLUMN_REFERENCE`); that will be fixed and tested in a 
separate PR.
   
   All tests pass. `dev/lint-python` passes.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5 (Anthropic), used as a pair-programming 
assistant. The author reviewed every line, ran the tests, and verified the 
coverage results locally.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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