Akanksha-kedia opened a new pull request, #18779:
URL: https://github.com/apache/pinot/pull/18779

   ## Description
   
   Adds the SQL standard `TRANSLATE(string, from, to)` scalar function to 
`StringFunctions`. This function performs character-level substitution: each 
character in `from` is replaced by the corresponding character in `to`. 
Characters in `string` that appear in `from` but have no corresponding `to` 
character (i.e. `from` is longer than `to`) are deleted from the output.
   
   This matches the behavior documented in PostgreSQL (`translate`), Oracle 
(`TRANSLATE`), and Trino (`translate`).
   
   ### Examples
   
   ```sql
   translate('hello', 'aeiou', 'AEIOU')  → 'hEllO'
   translate('abc',   'abc',   'xy')     → 'xy'       -- 'c' has no target → 
deleted
   translate('abcdef','ace',   'XY')     → 'XbYdf'    -- 'e' has no target → 
deleted
   translate('abc',   'abc',   '')       → ''          -- all chars deleted
   translate('hello', 'xyz',   '123')    → 'hello'    -- no match → unchanged
   ```
   
   ### Implementation
   
   Pure Java loop over the input string, using `String.indexOf()` to look up 
each character in the `from` string. O(n × |from|) — same complexity as the 
PostgreSQL implementation and appropriate for typical string sizes.
   
   ## Tests
   
   Unit tests added in `StringFunctionsTest` covering: basic replacement, 
deletion, no-op (no match), empty input, empty `from`, all-deleted output, and 
duplicate characters in `from`.
   
   ## Checklist
   
   - [x] New public API has documentation (Javadoc on the method)
   - [x] Backward compatible change (new function, no existing behavior changed)
   - [x] Follows existing `@ScalarFunction` patterns in `StringFunctions.java`


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