Gabriel39 commented on code in PR #71397:
URL: https://github.com/apache/doris/pull/71397#discussion_r4795149603


##########
be/src/format_v2/orc/orc_reader.cpp:
##########
@@ -2260,7 +2398,8 @@ Status OrcReader::_select_stripe_ranges_by_statistics() {
     uint64_t previous = range_first;
     for (size_t idx = 1; idx < selected_stripes.size(); ++idx) {
         const auto stripe_index = selected_stripes[idx];
-        if (stripe_index == previous + 1) {
+        if (stripe_index == previous + 1 &&
+            unsafe_date_stripes.contains(stripe_index) == 
unsafe_date_stripes.contains(previous)) {

Review Comment:
   Checked against the exact pinned ORC SDK 
d88650dcd09bf51907a68c0172052869b268002a. It caches the stripe prefix directory 
once and uses lower_bound for each range; the claimed whole-directory scan per 
RowReader does not occur. Added alternating 8/16-stripe tests in 2192e2e162: 
directory entries equal N and total RowReader stripe visits are at most 3N, 
including both cleanup readers. Directory/range traversal is O(N + R log N), 
not quadratic. Per-range schema setup remains O(R*C) and is explicitly noted; 
no production rewrite was made for the disproven directory-scan premise.



##########
be/src/format_v2/orc/orc_reader.cpp:
##########
@@ -2205,7 +2292,9 @@ Status OrcReader::_select_stripe_ranges_by_statistics() {
     int64_t filtered_bytes = 0;
     for (const auto stripe_index : split_stripes) {
         bool drop = false;
-        if (sarg_needed_stripes[stripe_index - split_stripes.front()] == 0) {
+        // An unsafe DATE must reach decoding, preserving strict errors or 
conversion-generated NULLs.
+        if (!unsafe_date_stripes.contains(stripe_index) &&

Review Comment:
   The reported ORC lazy-to-eager cache defect was fixed in 0b1a2ea661 and 
remains covered with pruning enabled/disabled. Explicit safe file bounds retain 
ordinary cache reuse; unsafe ranges preserve eager conversion errors. The 
pinned SDK caches a borrowed SARG applier, so cleanup consumes it while its 
options live and counts its readers.
   
   Correction to my earlier Parquet claim: the production 
FE/scanner/TableReader cache key includes strict-cast semantics. The injected 
reader test reused one context across incompatible settings and did not 
establish a production permissive-to-strict bypass. The unnecessary extra 
Parquet guard/test is removed in 2192e2e162; the independent COUNT/statistics 
fixes remain.



##########
be/src/format_v2/parquet/parquet_reader.cpp:
##########
@@ -1216,6 +1216,56 @@ Status ParquetReader::get_aggregate_result(const 
format::FileAggregateRequest& r
         }
         const auto& count_projection = request.columns[0].projection;
         const auto& root_schema = projected_root_schema(_state->file_schema, 
count_projection);
+        std::vector<const ParquetColumnSchema*> date_leaves;
+        if (_state->enable_strict_mode ||
+            remove_nullable(root_schema.type)->get_primitive_type() == 
TYPE_DATEV2) {
+            const auto collect_dates = [&](auto&& self, const 
ParquetColumnSchema& schema,
+                                           const format::LocalColumnIndex* 
projection) -> void {
+                if (schema.kind == ParquetColumnSchemaKind::PRIMITIVE) {
+                    if (remove_nullable(schema.type)->get_primitive_type() == 
TYPE_DATEV2) {
+                        date_leaves.push_back(&schema);
+                    }
+                    return;
+                }
+                for (const auto& child : schema.children) {
+                    if (format::is_child_projected(projection, 
child->local_id)) {
+                        self(self, *child,
+                             format::find_child_projection(projection, 
child->local_id));
+                    }
+                }
+            };
+            collect_dates(collect_dates, root_schema, &count_projection);
+        }
+        const auto& footer = _state->file_context.native_metadata->to_thrift();
+        // Older writers can publish incorrect all-NULL counts. They must not 
let COUNT
+        // bypass DATE conversion when the same statistics are distrusted by 
normal reads.
+        const bool null_count_trusted =
+                native::parquet_reader_compat(footer.__isset.created_by ? 
footer.created_by : "")
+                        .null_count_trusted;
+        for (const auto* date_leaf : date_leaves) {
+            // Definition levels count physical NULLs only. DATE conversion 
can add logical NULLs
+            // or raise an error, including for nested children in strict 
mode. Validate every
+            // projected DATE leaf before allowing a levels-only count to 
bypass conversion.
+            for (const auto& row_group_plan : _state->scan_plan->row_groups) {
+                const auto& group = 
_state->file_context.native_metadata->to_thrift()
+                                            
.row_groups[row_group_plan.row_group_id];
+                const auto& chunk = group.columns[date_leaf->leaf_column_id];
+                if (!chunk.__isset.meta_data || 
!chunk.meta_data.__isset.statistics) {
+                    return Status::NotSupported("Parquet DATE COUNT requires 
value validation");
+                }
+                const auto stats = detail::sanitize_native_footer_statistics(
+                        date_leaf->type_descriptor, chunk.meta_data.statistics,
+                        detail::has_supported_type_defined_order(
+                                
_state->file_context.native_metadata->to_thrift(),
+                                date_leaf->leaf_column_id));
+                const auto decoded = 
ParquetStatisticsUtils::TransformColumnStatistics(
+                        *date_leaf, &stats, chunk.meta_data.num_values, 
_state->timezone,
+                        null_count_trusted);
+                if (!decoded.has_min_max && !(decoded.has_null_count && 
!decoded.has_not_null)) {

Review Comment:
   The complete-bounds all-NULL contradiction was fixed in 0b1a2ea661. My 
earlier claim that partial/deprecated bounds were already protected before 
normalization was incorrect. The additional sanitizer fix in 2192e2e162 removes 
the null-count proof when raw DATE bounds were discarded. Required/nullable 
reader regressions now cover both single-bound forms and missing TYPE_ORDER, as 
well as complete contradictory bounds. Legitimate Parquet all-NULL shortcuts 
remain covered. COUNT retains its conversion-safety proof; the unrelated extra 
Parquet cache guard/test has been removed after tracing the real session-aware 
cache key.



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