maytasm commented on code in PR #19718:
URL: https://github.com/apache/druid/pull/19718#discussion_r3633711449


##########
sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java:
##########
@@ -517,6 +536,118 @@ private Iterator<AvailableSegmentMetadata> 
getAuthorizedAvailableSegments(
       return authorizedSegments.iterator();
     }
 
+    /**
+     * Best-effort extraction of an exact-match {@code datasource} constraint 
(column
+     * {@link #DATASOURCE_COLUMN}) from the pushed-down filters, so 
sys.segments can restrict its scan
+     * to the matching datasources rather than materializing every segment in 
the cluster. Handles
+     * {@code datasource = 'x'}, {@code datasource IN (...)} (normalized by 
Calcite to SEARCH),
+     * OR-of-equalities, and conjunctions - including a whole {@code WHERE} 
passed as a single
+     * {@code AND(...)} RexCall (as Calcite's filter-scan rule may do), where 
any non-datasource
+     * conjunct (e.g. {@code is_active = 1}) is simply ignored. Returns {@code 
null} when no usable
+     * datasource predicate is present, in which case the previous full-scan 
behavior is retained.
+     * Because the filters are not removed from the planner's filter list, 
Calcite still applies them
+     * and correctness holds even if this extraction is conservative or 
over-broad.
+     */
+    @Nullable
+    static Set<String> getDataSourceFilter(List<RexNode> filters)

Review Comment:
   nit: there's a similar function in 
SystemServerPropertiesTable#extractColumnEqualityFilters. Do you think this can 
be combine / reuse / refactor somehow? (Also, I think the server filtering 
would also benefit from handling IN, AND, OR, etc that you have in this 
function)



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