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

   ### What changes were proposed in this pull request?
   
   [SPARK-61206](https://issues.apache.org/jira/browse/SPARK-61206): Escape the 
backslashes of the comments in `DataType::to_ddl`, as Spark's DDL does.
   
   `DataType::to_ddl` (and the nested `sql_type` of its struct fields) writes a 
field comment as `COMMENT '...'`, with only its single quotes escaped. The 
backslashes are now escaped too, first and then the quotes, as Spark's 
`escapeSingleQuotedString` does:
   
   - `a\b` is written as `COMMENT 'a\\b'`,
   - `it's` as `COMMENT 'it\'s'`, and `ends\` as `COMMENT 'ends\\'`.
   
   The official `StructType.toDDL()` writes the same text for these comments, 
and the server reads each one back as it was. The newline and the other 
characters are written as before.
   
   ### Why are the changes needed?
   
   With the old escaping, the server's parser read the backslash of a comment 
as an escape sequence. A comment `a\b` was written as `COMMENT 'a\b'`, which 
the server reads as `a` followed by a backspace character (U+0008). A trailing 
backslash, or a backslash before a quote, broke the literal. The data changed 
silently, or the DDL failed to parse, for any comment with a backslash.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. `DataType::to_ddl` (Rust API only) writes the backslashes of a comment 
escaped. The DDL of a comment without a backslash does not change.
   
   ### How was this patch tested?
   
   - New tests at the end of `crates/spark-connect/tests/types_roundtrip.rs`:
     - `to_ddl_escapes_the_comments_as_spark_does` checks the DDL of comments 
with a backslash, a quote, an escaped quote, a trailing backslash and a 
newline, with and without NOT NULL.
     - `to_ddl_comments_round_trip_through_the_server_parser` parses the DDL 
with the server (`session.parse_ddl`) and checks that each comment comes back 
as it was. It runs when `SPARK_REMOTE` is set.
     - Both tests fail on the code before this change (the backslash comments) 
and pass with it.
   - The official PySpark 4.3.0 `StructType.toDDL()` gives the same DDL text 
for each of these comments, and the same round trip, against the same server.
   - With `SPARK_REMOTE` set to a local Spark 4.3.0 server, `cargo test -p 
apache-spark-connect --release --test types_roundtrip` (12 passed), the server 
round trip included.
   - The lib tests of both crates (618 passed), the build of all tests, also 
with `wasm-udf`, and the offline Python suites (2456 passed, 8 skipped); 
rustfmt passes, and clippy reports no diagnostics in the changed lines. CI runs 
the e2e and live suites.
   
   ### 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