alamb opened a new issue #935:
URL: https://github.com/apache/arrow-datafusion/issues/935


   **Is your feature request related to a problem or challenge? Please describe 
what you are trying to do.**
   The more standard SQL datafusion supports, the easier it will be to 
integrate it into the rest of the analytics ecosystem
   
   **Describe the solution you'd like**
   I would like to be able to run the following queries without error:
   
   ```shell
   cargo run --bin datafusion-cli
   ```
   
   ```sql
   -- works
   SELECT TRIM('  bar   ');
   
   -- does not work (examples from mysql)
   SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
   SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
   SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
   ```
   
   Actual output:
   ```sql
   > SELECT TRIM('  bar   ');
   
   +------------------------+
   | trim(Utf8("  bar   ")) |
   +------------------------+
   | bar                    |
   +------------------------+
   1 row in set. Query took 0.003 seconds.
   
   
   > SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
   Plan("TRIM LEADING is not yet supported ")
   
   > SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
   Plan("TRIM BOTH is not yet supported ")
   
   > SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
   Plan("TRIM TRAILING is not yet supported ")
   ```
   
   **Describe alternatives you've considered**
   A clear and concise description of any alternative solutions or features 
you've considered.
   
   **Additional context**
   SQL (postgres and mysql) offer support for extended `TRIM` syntax, and with 
https://github.com/apache/arrow-datafusion/pull/934 DataFusion's SQL parser can 
parse this syntax.
   
   Here are links to the references:
   * https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_trim
   * https://www.postgresql.org/docs/current/functions-string.html
   
   Here is a copy of the syntax from the mysql manual:
   
   ```
   TRIM([{BOTH | LEADING | TRAILING} [remstr] FROM] str), TRIM([remstr FROM] 
str)
   
   Returns the string str with all remstr prefixes or suffixes removed. If none 
of the specifiers BOTH, LEADING, or TRAILING is given, BOTH is assumed. remstr 
is optional and, if not specified, spaces are removed.
   
   mysql> SELECT TRIM('  bar   ');
           -> 'bar'
   mysql> SELECT TRIM(LEADING 'x' FROM 'xxxbarxxx');
           -> 'barxxx'
   mysql> SELECT TRIM(BOTH 'x' FROM 'xxxbarxxx');
           -> 'bar'
   mysql> SELECT TRIM(TRAILING 'xyz' FROM 'barxxyz');
           -> 'barx'
   ```
   


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