clintropolis commented on code in PR #18342:
URL: https://github.com/apache/druid/pull/18342#discussion_r2245013497
##########
processing/src/main/java/org/apache/druid/segment/AggregateProjectionMetadata.java:
##########
@@ -554,9 +616,73 @@ public String toString()
", aggregators=" + Arrays.toString(aggregators) +
", ordering=" + ordering +
", timeColumnPosition=" + timeColumnPosition +
- ", granularity=" + granularity +
+ ", effectiveGranularity=" + effectiveGranularity +
", orderingWithTimeSubstitution=" + orderingWithTimeSubstitution +
'}';
}
}
+
+ /**
+ * Rewrites a query {@link Filter} if possible, removing the {@link Filter}
of a projection. To match a projection
+ * filter, the query filter must be equal to the projection filter, or must
contain the projection filter as the child
+ * of an AND filter. This method returns null
+ * indicating that a rewrite is impossible with the implication that the
query cannot use the projection because the
+ * projection doesn't contain all the rows the query would match if not
using the projection.
+ */
+ @Nullable
+ public static Filter rewriteFilter(@Nullable Filter projectionFilter,
@Nullable Filter queryFilter)
+ {
+ if (projectionFilter == null || queryFilter == null) {
+ return queryFilter;
+ }
+ if (queryFilter.equals(projectionFilter)) {
+ return ProjectionFilterMatch.INSTANCE;
+ }
+ if (queryFilter instanceof IsBooleanFilter && ((IsBooleanFilter)
queryFilter).isTrue()) {
+ final IsBooleanFilter isTrueFilter = (IsBooleanFilter) queryFilter;
+ final Filter rewritten = rewriteFilter(projectionFilter,
isTrueFilter.getBaseFilter());
+ if (rewritten == null) {
+ return null;
+ }
+ //noinspection ObjectEquality
+ if (rewritten == ProjectionFilterMatch.INSTANCE) {
+ return ProjectionFilterMatch.INSTANCE;
+ }
+ return new IsBooleanFilter(rewritten, true);
+ }
+ if (queryFilter instanceof AndFilter) {
+ AndFilter andFilter = (AndFilter) queryFilter;
+ List<Filter> newChildren =
Lists.newArrayListWithExpectedSize(andFilter.getFilters().size());
+ boolean childRewritten = false;
+ for (Filter filter : andFilter.getFilters()) {
+ Filter rewritten = rewriteFilter(projectionFilter, filter);
+ //noinspection ObjectEquality
+ if (rewritten == ProjectionFilterMatch.INSTANCE) {
+ childRewritten = true;
+ } else {
+ if (rewritten != null) {
+ newChildren.add(rewritten);
+ childRewritten = true;
+ } else {
+ newChildren.add(filter);
+ }
+ }
+ }
+ // at least one child must have been rewritten to rewrite the AND
+ if (childRewritten) {
+ if (newChildren.size() > 1) {
Review Comment:
i think not with the current rather weak equals based matching logic -
either the parent AND would match a projection AND, or at most a single child
of this AND can match. Doing an overlap of AND children would be an
improvement, and run into the problem you're asking about I think. I'll see if
I can wire that up tho since it seems important for a query with something like
`x = 'a' and y = 'b' and z = 'c'` to match a projection with `x = 'a' and y =
'b'`
--
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]