github-actions[bot] commented on code in PR #68649:
URL: https://github.com/apache/doris/pull/68649#discussion_r4140242333


##########
be/src/format_v2/orc/orc_reader.cpp:
##########
@@ -1502,6 +1522,52 @@ Status 
OrcReader::_init_search_argument_from_local_filters() {
     }
 
     try {
+        // SARG can skip rows before DATE decoding detects an invalid ordinal. 
File statistics
+        // must prove the selected DATE domains are representable before 
enabling SDK pruning.
+        const auto dates_are_representable = [&](const auto& self, const 
::orc::Type& type,
+                                                 const std::set<uint64_t>* 
projected_ids) -> bool {
+            if (projected_ids != nullptr && 
!projected_ids->contains(type.getColumnId())) {
+                return true;
+            }
+            if (type.getKind() == ::orc::TypeKind::DATE) {
+                const auto stats =
+                        
_state->reader->getColumnStatistics(cast_set<uint32_t>(type.getColumnId()));
+                if (stats == nullptr) {
+                    return false;
+                }
+                if (stats->getNumberOfValues() == 0) {
+                    return true;
+                }
+                segment_v2::ZoneMap zone_map;
+                return set_date_zone_map(*stats, &zone_map);
+            }
+            for (uint64_t child = 0; child < type.getSubtypeCount(); ++child) {
+                if (!self(self, *type.getSubtype(child), projected_ids)) {
+                    return false;
+                }
+            }
+            return true;
+        };
+        for (const auto column_id : _state->read_columns) {
+            if (is_virtual_column(column_id)) {
+                continue;
+            }
+            const auto& type =
+                    
*_state->root_type->getSubtype(static_cast<uint64_t>(column_id.value()));
+            const auto* projection = find_request_projection(*_request, 
column_id);
+            DORIS_CHECK(projection != nullptr);
+            std::set<uint64_t> projected_ids;
+            const bool partial = has_pruned_projection(*projection);
+            if (partial) {
+                // Match includeTypes exactly: an unread DATE sibling cannot 
raise a conversion
+                // error and must not disable pruning for the projected 
columns.
+                RETURN_IF_ERROR(collect_projected_type_ids(type, *projection, 
&projected_ids));
+            }
+            if (!dates_are_representable(dates_are_representable, type,
+                                         partial ? &projected_ids : nullptr)) {
+                return Status::OK();

Review Comment:
   [P2] Preserve SARG pruning for safe stripes in a file with an unsafe DATE. 
If one stripe contains a projected -719469 DATE at `id=7` and many other 
stripes have valid DATEs with `id` ranges excluding 7, this file-wide guard 
returns before installing any search argument. 
`_select_stripe_ranges_by_statistics()` then reads every stripe for `WHERE 
id=7`, although only the unsafe stripe needs to be read. Validate the selected 
DATE range per stripe, or otherwise retain the unsafe stripe while pruning safe 
excluded stripes, and cover the mixed-stripe case. The existing partial-STRUCT 
test concerns an unread DATE sibling, so it does not exercise this path.



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