xxlaykxx opened a new pull request, #55864:
URL: https://github.com/apache/arrow/pull/55864

   ### Rationale for this change
   
   When a TIME column is fetched as a timestamp through the Flight SQL ODBC 
driver, the converter in `GetConverter` (`odbc_impl/util.cc`) assumes a fixed 
unit instead of reading it from the array type:
   
   * `time64` is always treated as nanoseconds, so `time64[us]` values come 
back 1000x too small. For example, `12:34:56.123456` is returned as 
`00:00:45.296123`.
   * `time32` is always treated as milliseconds, so `time32[s]` values are also 
wrong.
   
   The result is silently wrong data, with no error. Only `time64[ns]` and 
`time32[ms]` are converted correctly.
   
   ### What changes are included in this PR?
   
   * The separate TIME32 and TIME64 to TIMESTAMP branches in `GetConverter` are 
replaced by one helper, `ConvertTimeToTodayTimestamp`, which reads the unit 
from the array's `TimeType`.
   * The helper adds today's date in that unit and casts to `timestamp(unit)`, 
so the result keeps the precision of the input.
   * Behaviour for `time64[ns]` and `time32[ms]` is unchanged.
   
   ### Are these changes tested?
   
   Yes. `util_test.cc` now has one conversion test per unit (`time32[s]`, 
`time32[ms]`, `time64[us]`, `time64[ns]`), replacing the two previous tests 
that covered only milliseconds and nanoseconds. Each test also checks that the 
resulting timestamp has the same unit as the input.
   
   ### Are there any user-facing changes?
   
   Yes. ODBC clients now get correct values for `time64[us]` and `time32[s]` 
columns. There are no API changes.
   
   **This PR contains a "Critical Fix".** Before this change the driver 
returned incorrect TIME values for `time64[us]` and `time32[s]` columns without 
reporting an error.
   
   * GitHub Issue: #55860
   
   Thanks for opening a pull request!
   
   If this is your first pull request you can find detailed information on how 
to contribute here:
   
     * [New Contributor's 
Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
     * [Contributing 
Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
   
   Please remove this line and the above text before creating your pull request.
   
   ### Rationale for this change
   
   ### What changes are included in this PR?
   
   ### Are these changes tested?
   
   ### Are there any user-facing changes?
   
   **This PR includes breaking changes to public APIs.** (If there are any 
breaking changes to public APIs, please explain which changes are breaking. If 
not, you can remove this.)
   
   **This PR contains a "Critical Fix".** (If the changes fix either (a) a 
security vulnerability, (b) a bug that caused incorrect or invalid data to be 
produced, or (c) a bug that causes a crash (even when the API contract is 
upheld), please provide explanation. If not, you can remove this.)
   
   ### Was AI used for this PR?
   
   In accordance to the [AI generation 
guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code),
 please disclose below whether and how AI was used in this PR.
   
   **PR code and description written by:**
   
   - [ ] Human
   - [ ] AI
   
   **Reviewed before submission by:**
   
   - [ ] Human
   - [ ] AI
   - [ ] Not reviewed
   
   * GitHub Issue: (filled in automatically from the PR title; change "Closes" 
to "Refs" for a partial fix)
   


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