Skip to content

Commit

Permalink
[SPARK-45361][SQL][DOCS] Describe characters unescaping in string lit…
Browse files Browse the repository at this point in the history
…erals

### What changes were proposed in this pull request?
In the PR, I propose to update the doc ([link](https://spark.apache.org/docs/latest/sql-ref-literals.html#string-literal)) about string literals, and describe unescaping.
<img width="1193" alt="Screenshot 2023-09-28 at 21 23 01" src="https://github.com/apache/spark/assets/1580697/7b871ded-50e1-4c93-9d86-60a2ce93f5e7">

### Why are the changes needed?
To make clear how string literals are preprocessed. This should less confuse Spark SQL users.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
By building docs.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes #43152 from MaxGekk/doc-string-literal.

Authored-by: Max Gekk <max.gekk@gmail.com>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
  • Loading branch information
MaxGekk authored and dongjoon-hyun committed Oct 3, 2023
1 parent 5b80639 commit 39228d4
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/sql-ref-literals.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ A string literal is used to specify a character string value.

Case insensitive, indicates `RAW`. If a string literal starts with `r` prefix, neither special characters nor unicode characters are escaped by `\`.

The following escape sequences are recognized in regular string literals (without the `r` prefix), and replaced according to the following rules:
- `\0` -> `\u0000`, unicode character with the code 0;
- `\b` -> `\u0008`, backspace;
- `\n` -> `\u000a`, linefeed;
- `\r` -> `\u000d`, carriage return;
- `\t` -> `\u0009`, horizontal tab;
- `\Z` -> `\u001A`, substitute;
- `\%` -> `\%`;
- `\_` -> `\_`;
- `\<other char>` -> `<other char>`, skip the slash and leave the character as is.

#### Examples

```sql
Expand Down

0 comments on commit 39228d4

Please sign in to comment.