lyne7-sc opened a new issue, #23640:
URL: https://github.com/apache/datafusion/issues/23640

   ### Describe the bug
   
   The formatted variants of `to_date`, `to_timestamp*`, and `to_unixtime` do 
not handle some NULL string and format arguments consistently.
   
   There are three related cases:
   
   1. A NULL scalar string input produces an internal error.
   2. When all scalar format arguments are NULL, an internal error is produced.
   3. When an array format argument is NULL for the current row, it is read as 
an empty format string instead of being skipped.
   
   `to_date` and `to_timestamp*` use the affected shared implementation in 
`datetime/common.rs`. String inputs to `to_unixtime` delegate to 
`to_timestamp_seconds`, so they are affected by the same issue.
   
   
   ### To Reproduce
   
   A NULL scalar string input produces an internal error:
   
   ```sql
   SELECT to_date(NULL::VARCHAR, '%Y-%m-%d');
   ```
   
   ```text
   Internal error: a should not be None.
   ```
   
   The same issue affects formatted `to_timestamp*` and `to_unixtime` calls:
   
   ```sql
   SELECT to_timestamp(NULL::VARCHAR, '%Y-%m-%d');
   SELECT to_unixtime(NULL::VARCHAR, '%Y-%m-%d');
   ```
   
   When all scalar formats are NULL:
   
   ```sql
   SELECT to_date('2020-09-08', NULL::VARCHAR, NULL::VARCHAR);
   ```
   
   ```text
   Internal error: ret should not be None.
   ```
   
   A NULL format in an array argument is read as an empty format string instead 
of being skipped for the current row. The following multi-row input ensures the 
format arguments are evaluated as arrays:
   
   ```sql
   SELECT id, to_date(value, format1, format2)
   FROM (
     VALUES
       (1, '2020-09-08', NULL::VARCHAR, NULL::VARCHAR),
       (2, '2020-09-08', '%Y-%m-%d', NULL::VARCHAR)
   ) AS t(id, value, format1, format2)
   ORDER BY id;
   ```
   
   The first row produces:
   
   ```text
   Execution error: Error parsing timestamp from '2020-09-08' using format '': 
trailing input
   ```
   
   
   ### Expected behavior
   
   - A NULL scalar string input should return NULL.
   - NULL format arguments should be skipped.
   - If all candidate formats are NULL, the result should be NULL.
   - If at least one non-NULL format is provided but all non-NULL formats fail 
to parse the input, the existing parsing error behavior should be preserved.
   
   This is consistent with the existing NULL propagation behavior of the 
unformatted date/time conversion paths, formatted array inputs with NULL source 
values, and other date/time formatting functions such as `to_char`.
   
   
   ### Additional context
   
   _No response_


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