hello-stephen commented on code in PR #71397:
URL: https://github.com/apache/doris/pull/71397#discussion_r4795415967


##########
be/src/format_v2/parquet/reader/variant_column_reader.cpp:
##########
@@ -695,6 +701,10 @@ bool supports_direct_typed_variant_state(const 
ParquetColumnSchema& schema) {
     if (schema.type == nullptr || schema.kind != 
ParquetColumnSchemaKind::PRIMITIVE) {
         return false;
     }
+    // Raw INT32 is only physical storage here; an integer typed state would 
lose DATE identity.
+    if (schema.type_descriptor.is_variant_date) {

Review Comment:
   [P2] Preserve casts of year-zero shredded Variant DATE leaves
   
   A fully shredded Variant object with DATE leaf `v['d'] = 0000-03-01` has 
ordinal -719468, which was already decoded correctly on the base. Previously 
`find_typed_value()` returned a DATEV2 typed leaf, so `CAST(v['d'] AS DATE)` 
used the identity cast. This guard now sends even that representable leaf to 
`normalize_projected_primitive_leaf()`, and the encoded cast calls 
`append_date()` in 
`be/src/exprs/function/cast/variant_v2/cast_variant_to_scalar.cpp`, which 
rejects every year below 1. The same valid value now becomes SQL NULL (or a 
cast failure). Use the shared checked Gregorian inverse in the encoded 
DATE-to-scalar conversion, rejecting the actual unrepresentable leap day rather 
than all of year zero. Add a nested shredded/unshredded DATE cast test; the new 
root-scalar JSON/ordinal tests don't exercise this path.



##########
be/src/format_v2/orc/orc_reader.cpp:
##########
@@ -2374,9 +2523,17 @@ Status OrcReader::_create_row_reader() {
         if (_state->orc_lazy_read_enabled && _orc_filter == nullptr) {
             _orc_filter = std::make_unique<OrcFilterImpl>(this);
         }
+        // The SDK retains its SARG by reference; release the previous reader 
before replacing
+        // the options it borrowed. Keep the original SARG for later safe 
stripe ranges.
+        _state->row_reader.reset();
+        auto& options = _state->active_row_reader_options;
+        options = std::as_const(_state->row_reader_options);
+        if (_state->stripe_ranges_applied && 
!_state->selected_stripe_ranges.empty() &&
+            
_state->selected_stripe_ranges[_state->current_stripe_range].disable_sarg) {
+            options.searchArgument(nullptr);
+        }
         _state->row_reader = _state->reader->createRowReader(
-                _state->row_reader_options,
-                _state->orc_lazy_read_enabled ? _orc_filter.get() : nullptr,
+                options, _state->orc_lazy_read_enabled ? _orc_filter.get() : 
nullptr,

Review Comment:
   [P2] Preserve eager DATE errors through dictionary pruning
   
   For `SELECT d FROM orc_file WHERE s = 'mm'` with lazy materialization 
disabled, take a stripe whose DATE contains -719469 and whose string values are 
only 'aa' and 'zz'. The new preflight retains the unsafe DATE range and 
disables SARG, but this RowReader still receives `_string_dict_filter`. 
`onStringDictsLoaded()` can reject the stripe before DATE decoding; 
`get_block()` also materializes only dictionary-selected rows for partial 
matches. Direct string encoding reaches the eager DATE decoder and reports 
DATA_QUALITY_ERROR, while dictionary encoding can return a successful empty 
result for the same data. Dictionary filtering is independent of SARG (see the 
existing dictionary tests with min/max off). Apply the DATE-safety guard to 
eager dictionary pruning too, resetting stripe-local match state when switching 
ranges, and compare direct/dictionary scans with unsafe DATEs.



##########
be/src/core/column/variant_v2/column_variant_v2_typed_column.h:
##########
@@ -106,12 +106,15 @@ void with_variant_typed_scalar(const Column& column, 
size_t row, uint8_t scale,
     } else if constexpr (Type == TYPE_DECIMAL128I) {
         const __int128 value = column.get_data()[row].value;
         callback(VariantScalarRef::decimal(value, scale, 16));
-    } else if constexpr (Type == TYPE_DATE) {
-        const int32_t value = variant_days_since_epoch(column.get_data()[row], 
row, "DATE");
-        callback(VariantScalarRef::date(value));
-    } else if constexpr (Type == TYPE_DATEV2) {
-        const int32_t value = variant_days_since_epoch(column.get_data()[row], 
row, "DATEV2");
-        callback(VariantScalarRef::date(value));
+    } else if constexpr (Type == TYPE_DATE || Type == TYPE_DATEV2) {
+        const auto& value = column.get_data()[row];
+        if (!value.is_valid_date()) {
+            throw Exception(ErrorCode::INVALID_ARGUMENT,
+                            "Cannot encode invalid DATE value at row {} as 
Variant", row);
+        }
+        // Variant DATE uses Gregorian days; the MySQL offset shifts Jan/Feb 
of year zero.
+        // Keep DATETIME's separate timestamp mapping unchanged.
+        callback(VariantScalarRef::date(daynr_to_epoch_days(value.daynr())));

Review Comment:
   [P2] Convert legacy Variant storage DATE cells consistently
   
   This updates typed DATE emission, but `storage_date_days()` in 
`be/src/storage/segment/variant/v2/variant_storage_cell.cpp` still calls 
`variant_days_since_epoch()` (the old offset). For a supported historical 
sparse DATEV2 cell containing 0000-02-28, `decode_v1_storage_cells()` in its 
homogeneous typed path now emits -719470 (Feb 28); its generic fallback for a 
mixed batch emits -719469 (Feb 29). Full-object sparse reconstruction through 
`VariantAssembler::append_cell()` also uses that generic decoder, so the same 
stored value can differ between a direct path projection and full-object 
rendering. Share the checked Gregorian DATE conversion with the legacy-cell 
fallback without changing the separate DATETIME timestamp mapping, and add a 
typed-versus-generic legacy DATE-cell regression.



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