morningman opened a new issue, #67366:
URL: https://github.com/apache/doris/issues/67366

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/doris/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### Version
   
   Apache Doris 4.1.3-rc02, commit `31263df4dc1d4d3a27517d264802cd4d6b92c874`
   
   Client: Python + ADBC Flight SQL driver (`adbc_driver_flightsql`), FE 
`arrow_flight_sql_port` = 41070.
   The MySQL/JDBC protocol is used as the control path for comparison.
   
   ### What's Wrong?
   
   `DATE` values in year zero are shifted by one day when read over Arrow 
Flight SQL. `0000-01-01` (as returned by JDBC) is rendered as `0000-01-02` in 
Arrow, and `0000-02-28` is rendered as `0000-02-29`. Modern dates are not 
affected.
   
   The Flight SQL schema is `date32[day]` (and `list<date32[day]>` for arrays). 
The raw day value sent for `0000-01-01` is `-719527`, which PyArrow renders as 
`0000-01-02`. `2024-01-01` matches JDBC exactly.
   
   ### What You Expected?
   
   ADBC/Arrow and JDBC should return the same `DATE` value. `0000-01-01` and 
`0000-02-28` should not be shifted by the calendar conversion.
   
   ### How to Reproduce?
   
   1. Run the query over MySQL/JDBC and record the result.
   2. Run the same query over the Python ADBC Flight SQL driver.
   3. Compare the year-zero dates with the modern date.
   
   ```sql
   SELECT
     CAST('0000-01-01' AS DATE) AS d1,
     CAST('0000-02-28' AS DATE) AS d2,
     CAST('2024-01-01' AS DATE) AS modern_date;
   
   SELECT [CAST('0000-01-01' AS DATE)] AS date_array;
   ```
   
   Client side:
   
   ```python
   import adbc_driver_flightsql.dbapi as flight_sql
   
   conn = flight_sql.connect(uri="grpc://127.0.0.1:41070",
                             db_kwargs={"username": "root", "password": ""})
   cur = conn.cursor()
   cur.execute("SELECT CAST('0000-01-01' AS DATE), CAST('0000-02-28' AS DATE), 
CAST('2024-01-01' AS DATE)")
   print(cur.fetch_arrow_table().to_pylist())
   ```
   
   ### Anything Else?
   
   The off-by-one looks like a proleptic-Gregorian vs. Julian calendar mismatch 
in the day-number computation used to build the Arrow `date32` value; Arrow 
`date32` is defined as days since the epoch in the proleptic Gregorian calendar.
   
   **Workaround:** `CAST` the column to `STRING` in Doris and parse it on the 
client. This bypasses the Arrow `DATE` encoding but loses the native date type.
   
   Verified by comparing the raw Arrow day values against the JDBC results 
directly.
   
   Tracking issue: #65615
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


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