chovy-3012 commented on issue #13378:
URL: https://github.com/apache/seatunnel/issues/13378#issuecomment-7065647878

   
   **ENCODE / DECODE — proposed usage and special cases**
   
   ### ENCODE
   
   ```ENCODE(value, charset) -> BINARY```
   
   Encodes a string into a binary value using the provided character set.
   
   Supported charsets include `US-ASCII`, `ISO-8859-1`, `UTF-8`, `UTF-16BE`, 
`UTF-16LE`, `UTF-16`. Charset names are case-insensitive.
   
   This is charset conversion between a string and raw bytes, not Base64 text 
encoding; for Base64 use `TO_BASE64`.
   
   Example:
   
   ```
   select ENCODE(name, 'UTF-8') as name_binary
   
   select ENCODE(name, 'UTF-16BE') as name_binary
   
   select ENCODE(name, 'ISO-8859-1') as name_binary
   ```
   
   ### DECODE
   
   ```DECODE(value, charset) -> STRING```
   
   Decodes a binary value into a string using the provided character set.
   
   Supported charsets include `US-ASCII`, `ISO-8859-1`, `UTF-8`, `UTF-16BE`, 
`UTF-16LE`, `UTF-16`. Charset names are case-insensitive.
   
   For Base64 text use `FROM_BASE64`. The Oracle-style conditional 
`DECODE(expr, search, result [, default])` is not supported: a `DECODE` call 
with 3 or more arguments raises an argument-count error, and there is no 
conditional overload.
   
   Example:
   
   ```
   select DECODE(payload, 'ISO-8859-1') as payload_text
   
   select DECODE(ENCODE(name, 'UTF-8'), 'UTF-8') as name_roundtrip
   ```
   
   ### NULL handling
   
   Returns **NULL** if either argument is **NULL**:
   
   ```
   ENCODE(NULL, 'UTF-8')      -> NULL
   ENCODE(name, NULL)         -> NULL
   DECODE(NULL, 'UTF-8')      -> NULL
   DECODE(payload, NULL)      -> NULL
   ```
   
   ### Other special cases
   
   - **Unsupported charset name** — raises an explicit error; it never falls 
back silently to a default charset. Charset resolution goes through the JVM's 
charset support (case-insensitive), so any JVM-known name is accepted and 
unknown names are rejected.
   - **Wrong argument count** — raises an argument-count error. Both functions 
take exactly 2 arguments; the conditional-`DECODE` form does not exist.
   - **Wrong argument types** — raises an argument-type error. `ENCODE` 
requires a string value; `DECODE` requires a binary value.
   - **Invalid byte sequences** — when the binary input is not valid for the 
chosen charset, `DECODE` decodes with the JVM decoder's replacement behavior 
rather than raising, since the implementation reuses the existing string↔bytes 
conversion path.
   - **Round trip** — `DECODE(ENCODE(s, c), c)` returns `s` for the documented 
charsets.
   - **No transcoding or charset auto-detection** — the functions convert 
between a string and raw bytes only; converting text from one charset to 
another is a `DECODE` followed by an `ENCODE`.
   


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

Reply via email to