benbellick opened a new issue, #25425:
URL: https://github.com/apache/datafusion/issues/25425

   # date_trunc gives different scalar and array results for negative subsecond 
timestamps
   
   ## Describe the bug
   
   `date_trunc` can return different results for the same timestamp depending 
on whether it is evaluated as a scalar or a column value.
   
   For a timestamp of `-999` microseconds since the Unix epoch (`1969-12-31 
23:59:59.999001`), truncating to milliseconds returns:
   
   - Scalar input: `0` microseconds (`1970-01-01 00:00:00`).
   - Column input: `-1000` microseconds (`1969-12-31 23:59:59.999`), the 
expected result.
   
   ## To Reproduce
   
   ```sql
   SELECT
       CAST(date_trunc('millisecond',
           arrow_cast(-999, 'Timestamp(Microsecond, None)')) AS BIGINT) AS 
scalar_result_us,
       CAST(date_trunc('millisecond',
           arrow_cast(ts, 'Timestamp(Microsecond, None)')) AS BIGINT) AS 
column_result_us
   FROM (VALUES (-999)) AS timestamps(ts);
   ```
   
   Actual output:
   
   ```text
   scalar_result_us | column_result_us
   ----------------+-----------------
   0               | -1000
   ```
   
   Reproduced on commit `22651d24cc8196f3206e09a36a437eda9e766b87` (development 
version `55.1.0`).
   
   ## Expected behavior
   
   Both result columns should contain `-1000`. Truncating to milliseconds 
should produce the start of the containing millisecond, independently of scalar 
or array execution.
   
   ## Additional context
   
   The earlier fix in https://github.com/apache/datafusion/pull/18356 addressed 
negative timestamps in the array implementation; this report concerns the 
scalar/array discrepancy.
   


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