suxiaogang223 opened a new pull request, #60231:
URL: https://github.com/apache/doris/pull/60231

   ### What problem does this PR solve?
   
   Fixes a critical SIGSEGV crash when querying Hive Text external tables 
containing datetime fields with timezone information (e.g., `2023-01-01 
12:00:00+08:00` or `2023-01-01T12:00:00Z`) through Hive Catalog.
   
   ### Problem Summary
   
   When querying Hive Text external tables via Hive Catalog, BE crashes with 
SIGSEGV if:
   1. The data contains datetime strings with timezone information (e.g., 
`+08:00`, `Z`)
   2. The table schema defines the column as `timestamp` or `datetimev2` 
(without timezone)
   3. The column is included in the SELECT query
   
   **Stack trace:**
   ```
   #4  cctz::time_zone::lookup(...) const in doris_be
   #5  CastToDatetimeV2::from_string_strict_mode<false>(...) at 
cast_to_datetimev2_impl.hpp:634
   #6  DateV2Value<DateTimeV2ValueType>::from_date_str(...) at 
vdatetime_value.cpp:1794
   #7  DataTypeDateTimeV2SerDe::deserialize_one_cell_from_json(...) at 
data_type_datetimev2_serde.cpp:325
   ```
   
   ### Root Cause
   
   The issue occurs in the datetime parsing flow:
   
   1. **Call chain:** `TextReader/CsvReader → DataTypeDateTimeV2SerDe → 
DateV2Value::from_date_str → CastToDatetimeV2::from_string_strict_mode`
   
   2. **Null timezone issue:** `DateV2Value::from_date_str()` 
(vdatetime_value.cpp:1812) passes `nullptr` as the `local_time_zone` parameter:
      ```cpp
      return vectorized::CastToDatetimeV2::from_string_non_strict_mode(
          {date_str, len}, *this, nullptr, scale, params);
      ```
   
   3. **Timing problem:** In `cast_to_datetimev2_impl.hpp`, when parsing 
datetime strings with timezone:
      - Line 590-634: Parses timezone info into `parsed_tz`
      - Line 636-637: Creates `cctz::civil_second` object
      - **Line 644: Calls `cctz::convert(cs, parsed_tz)` - CRASH HERE when 
timezone is invalid/null**
      - Line 641-643: Checks `local_time_zone != nullptr` - TOO LATE!
   
   ### Solution
   
   Move the `local_time_zone != nullptr` validation **BEFORE** any timezone 
conversion operations:
   
   **Before:**
   ```cpp
   cctz::civil_second cs {res.year(), res.month(), res.day(), ...};
   if constexpr (type == DataTimeCastEnumType::DATE_TIME) {
       SET_PARAMS_RET_FALSE_IFN(local_time_zone != nullptr, "...");
       auto given = cctz::convert(cs, parsed_tz);  // May crash here
       auto local = cctz::convert(given, *local_time_zone);
   }
   ```
   
   **After:**
   ```cpp
   if constexpr (type == DataTimeCastEnumType::DATE_TIME) {
       SET_PARAMS_RET_FALSE_IFN(local_time_zone != nullptr, "..."); // Check 
first!
   }
   cctz::civil_second cs {res.year(), res.month(), res.day(), ...};
   if constexpr (type == DataTimeCastEnumType::DATE_TIME) {
       auto given = cctz::convert(cs, parsed_tz);  // Safe now
       auto local = cctz::convert(given, *local_time_zone);
   }
   ```
   
   This ensures the system fails gracefully with an error message instead of 
crashing.
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [ ] Regression test
       - [ ] Unit Test
       - [ ] Manual test (add detailed scripts or steps below)
       - [ ] No need to test or manual test. Explain why:
           - [ ] This is a refactor/code format and no logic has been changed.
           - [ ] Previous test can cover this change.
           - [ ] No code files have been changed.
           - [ ] Other reason <!-- Add your reason?  -->
   
   - Behavior changed:
       - [ ] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [ ] No.
       - [ ] Yes. <!-- Add document PR link here. eg: 
https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should 
merge into -->
   
   


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