chovy-3012 opened a new issue, #13378: URL: https://github.com/apache/seatunnel/issues/13378
### Search before asking - [x] I had searched in the [feature](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22Feature%22) and found no similar feature requirement. ### Description SQLTransform currently does not provide built-in functions for converting between string and binary values using a character set. The same function pair already exists in the three engines SeaTunnel users most often migrate SQL from: | Engine | Functions | Available since | |---|---|---| | Hive | `encode(str, charset)` / `decode(bin, charset)` | Hive 0.13 | | Spark SQL | `encode(str, charset)` / `decode(bin, charset)` | Spark 1.5 | | Flink SQL | `ENCODE(string1, string2)` / `DECODE(binary, string)` | Flink 1.16 | All three share the same semantics, and this issue proposes following that common usage: - `ENCODE(string, charset)` - encodes the string into a binary value using the charset - `DECODE(binary, charset)` - decodes the binary value into a string using the charset - Supported charsets: `US-ASCII`, `ISO-8859-1`, `UTF-8`, `UTF-16BE`, `UTF-16LE`, `UTF-16` - If either argument is null, the result is also null Note this is character-set conversion, not encryption (`AES_ENCRYPT` / `AES_DECRYPT` already exist) and not Base64 encoding (`TO_BASE64` / `FROM_BASE64` already exist). The Oracle-style conditional `DECODE(expr, search, result, default)` is out of scope - it is a Spark-specific extension and `CASE WHEN` already covers it. ## Goals - Add `ENCODE(string, charset)` to SQLTransform - Add `DECODE(binary, charset)` to SQLTransform - Support the six standard charsets listed above - Return null when either argument is null - Add unit tests and E2E tests - Update the SQL function docs in `docs/en` and `docs/zh` ### Usage Scenario Jobs migrated from Hive, Spark, or Flink that call `encode()` / `decode()` currently fail in SQLTransform and the SQL has to be rewritten. It is also needed when a source returns binary columns that hold text in a legacy charset (for example `ISO-8859-1`) and the text has to be restored before writing it downstream. ```sql select id, DECODE(payload, 'ISO-8859-1') as decoded_payload, ENCODE(name, 'UTF-16') as encoded_name from source_table ``` ### Related issues _No response_ ### Are you willing to submit a PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow the project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
