andygrove opened a new issue, #418:
URL: https://github.com/apache/datafusion-spark/issues/418

   ### Describe the bug
   
   DataFusion-spark treats `\t` and `\n` in SQL string literals as literal 
backslash characters, while Apache Spark interprets them as escape sequences 
(tab and newline). This affects any function that receives string arguments 
containing these sequences.
   
   ### To Reproduce
   
   **PySpark (Spark behavior):**
   ```sql
   SELECT soundex('\thello');  -- returns tab + "hello" (soundex passes through 
non-alpha input)
   SELECT soundex('\nhello');  -- returns newline + "hello"
   SELECT length('\thello');   -- 6 (tab is one character)
   SELECT length('\nhello');   -- 6 (newline is one character)
   ```
   
   **DataFusion-spark (current behavior):**
   ```sql
   SELECT soundex('\thello');  -- returns literal "\thello" (backslash-t-hello)
   SELECT soundex('\nhello');  -- returns literal "\nhello" (backslash-n-hello)
   SELECT length('\thello');   -- 7 (\t is two characters: backslash and t)
   SELECT length('\nhello');   -- 7 (\n is two characters: backslash and n)
   ```
   
   ### Expected behavior
   
   DataFusion-spark should interpret `\t`, `\n`, and other escape sequences in 
string literals the same way Spark does, for Spark compatibility.
   
   ### Additional context
   
   The fix belongs in sqlparser. `datafusion.sql_parser.dialect = spark` uses 
sqlparser's `SparkSqlDialect`, which doesn't override 
`supports_string_literal_backslash_escape` (default `false`), so `'\t'` is 
tokenized as a backslash and `t`. `DatabricksDialect` already returns `true`. 
Once `SparkSqlDialect` does the same, DataFusion only needs the sqlparser 
upgrade. The affected `.slt` expectations (for example `string/soundex.slt`) 
now live in apache/datafusion-spark.
   


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