clintropolis commented on code in PR #19791: URL: https://github.com/apache/druid/pull/19791#discussion_r3684865329
########## server/src/main/java/org/apache/druid/server/coordinator/rules/CompositePartialLoadMatcher.java: ########## @@ -0,0 +1,198 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.server.coordinator.rules; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.hash.Hasher; +import com.google.common.hash.Hashing; +import com.google.common.io.BaseEncoding; +import org.apache.druid.error.InvalidInput; +import org.apache.druid.segment.loading.CompositePartialLoadSpec; +import org.apache.druid.segment.loading.PartialLoadSpec; +import org.apache.druid.timeline.DataSegment; + +import javax.annotation.Nullable; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Objects; + +/** + * Combines several {@link PartialLoadMatcher}s so that one {@link PartialLoadRule} can contribute more than one kind + * of partial load to a segment. The resolved selection is the <em>union</em> of what the members select: partial-load + * a segment's projections and a subset of its cluster groups together, or express a single scheme's selection that + * its own matcher cannot, such as a disjoint union of include/exclude pattern pairs over the same clustering columns. + * <p> + * Composition is a union, not an ordered fallback. Members are not consulted in priority order and no member can + * shadow another; every member that resolves contributes, and the historical-side {@link CompositePartialLoadSpec} + * takes the union of their bundles. + * <p> + * <b>A member that does not apply vetoes the whole composite.</b> If any member returns {@code null}, it understands + * neither the segment's shape nor how to express a selection for it, e.g. a cluster-group matcher facing a segment + * that isn't clustered, or a matcher type this Druid version doesn't recognize (see {@link UnknownPartialLoadMatcher}) + * this matcher returns {@code null} too and the rule's {@link CannotMatchBehavior} decides for the whole segment. + * Skipping such a member instead would silently narrow the load: a composite whose cluster-group member went opaque + * would announce a segment holding only its projections and none of its rows, and queries against it would quietly + * return nothing. + */ +public class CompositePartialLoadMatcher implements PartialLoadMatcher +{ + public static final String TYPE = "composite"; + + static final String FINGERPRINT_VERSION = "v1"; + + private final List<PartialLoadMatcher> matchers; + + @JsonCreator + public CompositePartialLoadMatcher(@JsonProperty("matchers") List<PartialLoadMatcher> matchers) + { + if (matchers == null || matchers.isEmpty()) { + throw InvalidInput.exception("matchers must not be null or empty for composite matcher"); + } + for (int i = 0; i < matchers.size(); i++) { + if (matchers.get(i) == null) { + throw InvalidInput.exception("matchers[%s] must not be null for composite matcher", i); + } + } + this.matchers = List.copyOf(matchers); + } + + @JsonProperty + public List<PartialLoadMatcher> getMatchers() + { + return matchers; + } + + @Override + @Nullable + public MatchResult match(DataSegment segment, Map<String, Object> baseLoadSpec) + { + // Members get the real base load spec, not a stub: a member may legitimately inspect it, and its delegate is + // stripped afterward (see toMember) rather than withheld up front. + final List<MatchResult> results = new ArrayList<>(matchers.size()); + for (PartialLoadMatcher matcher : matchers) { + final MatchResult result = matcher.match(segment, baseLoadSpec); + if (result == null) { Review Comment: i was planning to make improvements to the projection matchers which would solve this in a follow-up PR. Projection matchers should basically never return null, and instead if the matching projection is not present it should issue a load-spec that tells things to load the 'base' table projection (since all projections can be computed from the table itself if the projection isn't present). -- 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]
