alamb opened a new pull request, #5117:
URL: https://github.com/apache/arrow-datafusion/pull/5117

   Draft as it
   - [ ] builds on https://github.com/apache/arrow-datafusion/pull/5115
   - [ ] Needs upstream arrow-rs to be filed
   - [ ] Needs 
   
   # Which issue does this PR close?
   
   Closes https://github.com/apache/arrow-datafusion/issues/4853
   
   
   
   # Rationale for this change
   
   
   
   Rationale:
   
   `date_bin` with a string value does not work and gives a hard to understand 
message:
   
   
   ```sql
   ❯  select date_bin('1 hour', column1, TIMESTAMP '2001-01-01 00:00:00Z')
   from (values
     (timestamp '2022-01-01 00:00:00'),
     (timestamp '2022-01-01 01:00:00'),
   (timestamp '2022-01-02 00:00:00')
   ) as sq;
   Plan("Coercion from [Utf8, Timestamp(Nanosecond, None), 
Timestamp(Nanosecond, None)] to the signature Exact([Interval(DayTime), 
Timestamp(Nanosecond, None), Timestamp(Nanosecond, None)]) failed.")
   ```
   
   # What changes are included in this PR?
   1. add coercion so that `Utf8` constants can be automatically coerced into 
Intervals (same as today)
   2. Add coercion so that `Utf8` can be automatically coerced into Timestamps
   3. 
   
   
   # Are these changes tested?
   Yes
   
   # Are there any user-facing changes?
   
   Yes, strings are now automatically coerced into `Timetamp`s and `Intervals`
   
   Note this behavior is consistent with Postgres:
   
   ```sql
   postgres=# SELECT DATE_BIN(INTERVAL '15 minutes', TIMESTAMP '2022-08-03 
14:38:50Z', TIMESTAMP '1970-01-01T00:00:00Z') AS res;
            res
   ---------------------
    2022-08-03 14:30:00
   (1 row)
   
   postgres=# SELECT DATE_BIN('15 minutes', TIMESTAMP '2022-08-03 14:38:50Z', 
TIMESTAMP '1970-01-01T00:00:00Z') AS res;
            res
   ---------------------
    2022-08-03 14:30:00
   (1 row)
   
   postgres=# SELECT DATE_BIN('15 minutes', '2022-08-03 14:38:50Z', 
'1970-01-01T00:00:00Z') AS res;
             res
   ------------------------
    2022-08-03 14:30:00+00
   (1 row)
   ```


-- 
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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to