clintropolis commented on code in PR #12753: URL: https://github.com/apache/druid/pull/12753#discussion_r932917683
########## processing/src/main/java/org/apache/druid/segment/NestedDataColumnMerger.java: ########## @@ -0,0 +1,272 @@ +/* + * 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.segment; + +import com.google.common.collect.PeekingIterator; +import org.apache.druid.java.util.common.ISE; +import org.apache.druid.java.util.common.Pair; +import org.apache.druid.java.util.common.io.Closer; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.segment.column.BaseColumn; +import org.apache.druid.segment.column.ColumnDescriptor; +import org.apache.druid.segment.column.ColumnHolder; +import org.apache.druid.segment.column.ValueType; +import org.apache.druid.segment.data.Indexed; +import org.apache.druid.segment.incremental.IncrementalIndex; +import org.apache.druid.segment.incremental.IncrementalIndexAdapter; +import org.apache.druid.segment.nested.CompressedNestedDataComplexColumn; +import org.apache.druid.segment.nested.GlobalDictionarySortedCollector; +import org.apache.druid.segment.nested.NestedDataColumnSerializer; +import org.apache.druid.segment.nested.NestedDataComplexTypeSerde; +import org.apache.druid.segment.nested.NestedLiteralTypeInfo; +import org.apache.druid.segment.serde.ComplexColumnPartSerde; +import org.apache.druid.segment.writeout.SegmentWriteOutMedium; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.nio.IntBuffer; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; + +public class NestedDataColumnMerger implements DimensionMergerV9 +{ + private static final Logger log = new Logger(NestedDataColumnMerger.class); + public static final Comparator<Pair<Integer, PeekingIterator<Long>>> LONG_MERGING_COMPARATOR = + DictionaryMergingIterator.makePeekingComparator(); + public static final Comparator<Pair<Integer, PeekingIterator<Double>>> DOUBLE_MERGING_COMPARATOR = + DictionaryMergingIterator.makePeekingComparator(); + + private final String name; + private final Closer closer; + + private NestedDataColumnSerializer serializer; + + public NestedDataColumnMerger( + String name, + IndexSpec indexSpec, + SegmentWriteOutMedium segmentWriteOutMedium, + ProgressIndicator progressIndicator, + Closer closer + ) + { + + this.name = name; + this.serializer = new NestedDataColumnSerializer(name, indexSpec, segmentWriteOutMedium, progressIndicator, closer); + this.closer = closer; + } + + @Override + public void writeMergedValueDictionary(List<IndexableAdapter> adapters) throws IOException + { + + long dimStartTime = System.currentTimeMillis(); + + int numMergeIndex = 0; + GlobalDictionarySortedCollector sortedLookup = null; + final Indexed[] sortedLookups = new Indexed[adapters.size()]; + final Indexed[] sortedLongLookups = new Indexed[adapters.size()]; + final Indexed[] sortedDoubleLookups = new Indexed[adapters.size()]; + + final SortedMap<String, NestedLiteralTypeInfo.MutableTypeSet> mergedFields = new TreeMap<>(); + + for (int i = 0; i < adapters.size(); i++) { + final IndexableAdapter adapter = adapters.get(i); + final GlobalDictionarySortedCollector dimValues; + if (adapter instanceof IncrementalIndexAdapter) { + dimValues = getSortedIndexFromIncrementalAdapter((IncrementalIndexAdapter) adapter, mergedFields); + } else if (adapter instanceof QueryableIndexIndexableAdapter) { + dimValues = getSortedIndexesFromQueryableAdapter((QueryableIndexIndexableAdapter) adapter, mergedFields); + } else { + throw new ISE("Unable to merge columns of unsupported adapter %s", adapter.getClass()); + } + + boolean allNulls = allNull(dimValues.getSortedStrings()) && + allNull(dimValues.getSortedLongs()) && + allNull(dimValues.getSortedDoubles()); + sortedLookup = dimValues; Review Comment: nah, this is a strange flow that i picked up from this code being based on `DictionaryEncodedColumnMerger`. Every iteration sets sortedLookup, which is only used if there is a single thing being "merged", which _really_ means that an incremental index is being persisted. If there are more than 1 set things being merged, then it uses a `DictionaryMergingIterator` for each locally sorted set of values to merge them, which null values in the array are just skipped. Its probably worth adjusting this code, will try to re-arrange in the future so its a bit easier to follow. -- 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]
