clintropolis commented on code in PR #18119:
URL: https://github.com/apache/druid/pull/18119#discussion_r2145550975
##########
processing/src/main/java/org/apache/druid/segment/AggregateProjectionMetadata.java:
##########
@@ -119,6 +122,34 @@ public String toString()
'}';
}
+ /**
+ * Merge two maps of {@link AggregateProjectionMetadata} objects, returning
a new map with the same keys and merged
+ * metadata. If the schemas do not match, the metadata is not merged and the
key is not included in the result.
+ *
+ * @param projections1 first map of projections to merge
+ * @param projections2 second map of projections to merge
+ * @return merged map of projections
+ */
+ public static Map<String, AggregateProjectionMetadata> merge(
Review Comment:
I think this logic should be part of the segment metadata query stuff
instead of living here since it is specific to that query, so it isn't
unintentionally used for other purposes. Similarly, the `Metadata` class has
its own logic that it uses when combining the `Metadata` during segment
creation, though with different logic that is validating the projections are
all the same:
https://github.com/apache/druid/blob/master/processing/src/main/java/org/apache/druid/segment/Metadata.java#L344
##########
processing/src/main/java/org/apache/druid/query/metadata/metadata/SegmentMetadataQuery.java:
##########
@@ -59,7 +59,8 @@ public enum AnalysisType implements Cacheable
MINMAX,
TIMESTAMPSPEC,
QUERYGRANULARITY,
- ROLLUP;
+ ROLLUP,
+ PROJECTIONS;
Review Comment:
will need to update the docs to include this new analysis type too at some
point,
https://github.com/apache/druid/blob/master/docs/querying/segmentmetadataquery.md#analysistypes,
and also include the fact that when merging results that any mismatched
projections will be omitted. It would be fine to do this as a follow-up or part
of this PR is fine too
##########
processing/src/test/java/org/apache/druid/query/metadata/SegmentAnalysisBuilder.java:
##########
@@ -0,0 +1,131 @@
+/*
+ * 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.query.metadata;
+
+import org.apache.druid.query.aggregation.AggregatorFactory;
+import org.apache.druid.query.metadata.metadata.ColumnAnalysis;
+import org.apache.druid.query.metadata.metadata.SegmentAnalysis;
+import org.apache.druid.segment.AggregateProjectionMetadata;
+import org.apache.druid.timeline.SegmentId;
+import org.joda.time.Interval;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Helper class to build {@link SegmentAnalysis} objects for testing purposes.
+ */
+public class SegmentAnalysisBuilder
Review Comment:
nit: we commonly put builders inside of the class they build as an internal
class just named like `Builder`, which i think helps with visibility, so people
already looking at a class know it has a builder, and just have a static method
like `SegmentAnalysis.builder().addFoo(..).build()`
##########
processing/src/main/java/org/apache/druid/segment/IndexMergerV9.java:
##########
@@ -302,20 +270,21 @@ private File makeIndexFiles(
progress.stopSection(section);
- if (segmentMetadata != null &&
!CollectionUtils.isNullOrEmpty(segmentMetadata.getProjections())) {
- segmentMetadata = makeProjections(
- v9Smoosher,
- segmentMetadata.getProjections(),
- adapters,
- indexSpec,
- segmentWriteOutMedium,
- progress,
- outDir,
- closer,
- mergersMap,
- segmentMetadata
- );
- }
+ // Recompute the projections.
+ final Metadata finalMetadata =
+ segmentMetadata == null ||
CollectionUtils.isNullOrEmpty(segmentMetadata.getProjections())
+ ? segmentMetadata
+ : makeProjections(v9Smoosher,
+ segmentMetadata.getProjections(),
+ adapters,
+ indexSpec,
+ segmentWriteOutMedium,
+ progress,
+ outDir,
+ closer,
+ mergersMap,
+ segmentMetadata
+ );
Review Comment:
nit: this is less ugly as an `if` statement
--
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]