siddharthteotia commented on a change in pull request #7885: URL: https://github.com/apache/pinot/pull/7885#discussion_r768308452
########## File path: pinot-segment-spi/src/main/java/org/apache/pinot/segment/spi/creator/IndexCreationContext.java ########## @@ -0,0 +1,256 @@ +/** + * 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.pinot.segment.spi.creator; + +import java.io.File; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.apache.pinot.segment.spi.ColumnMetadata; +import org.apache.pinot.segment.spi.compression.ChunkCompressionType; +import org.apache.pinot.segment.spi.index.creator.H3IndexConfig; +import org.apache.pinot.spi.config.table.BloomFilterConfig; +import org.apache.pinot.spi.config.table.FSTType; +import org.apache.pinot.spi.data.FieldSpec; + + +public class IndexCreationContext { + + public static final class Builder { + private File _indexDir; + private Map<String, Map<String, String>> _columnProperties; + private FSTType _fstType; + private H3IndexConfig _h3IndexConfig; + private int _lengthOfLongestEntry; + private int _maxNumberOfMultiValueElements; + private int _maxRowLengthInBytes; + private Object _sortedUniqueElementsArray; + private boolean _onHeap = false; + private ChunkCompressionType _chunkCompressionType; + public BloomFilterConfig _bloomFilterConfig; + private int _rangeIndexVersion; + private ColumnMetadata _columnMetadata; + + public Builder withColumnIndexCreationInfo(ColumnIndexCreationInfo columnIndexCreationInfo) { + return withLengthOfLongestEntry(columnIndexCreationInfo.getLengthOfLongestEntry()) + .withMaxNumberOfMultiValueElements(columnIndexCreationInfo.getMaxNumberOfMultiValueElements()) + .withMaxRowLengthInBytes(columnIndexCreationInfo.getMaxRowLengthInBytes()) + .withSortedUniqueElementsArray(columnIndexCreationInfo.getSortedUniqueElementsArray()); + } + + public Builder withIndexDir(File indexDir) { + _indexDir = indexDir; + return this; + } + + public Builder withSegmentGeneratorConfig(@Nonnull SegmentGeneratorConfig segmentGeneratorConfig) { + return onHeap(segmentGeneratorConfig.isOnHeap()) + .withColumnProperties(segmentGeneratorConfig.getColumnProperties()); + } + + public Builder onHeap(boolean onHeap) { + _onHeap = onHeap; + return this; + } + + public Builder withColumnProperties(Map<String, Map<String, String>> columnProperties) { + _columnProperties = columnProperties; + return this; + } + + public Builder withColumnMetadata(ColumnMetadata columnMetadata) { + _columnMetadata = columnMetadata; + return this; + } + + public Builder withFSTType(FSTType fstType) { + _fstType = fstType; + return this; + } + + public Builder withH3IndexConfig(H3IndexConfig h3IndexConfig) { + _h3IndexConfig = h3IndexConfig; + return this; + } + + public Builder withLengthOfLongestEntry(int lengthOfLongestEntry) { + _lengthOfLongestEntry = lengthOfLongestEntry; + return this; + } + + public Builder withMaxNumberOfMultiValueElements(int maxNumberOfMultiValueElements) { + _maxNumberOfMultiValueElements = maxNumberOfMultiValueElements; + return this; + } + + public Builder withMaxRowLengthInBytes(int maxRowLengthInBytes) { + _maxRowLengthInBytes = maxRowLengthInBytes; + return this; + } + + public Builder withSortedUniqueElementsArray(Object sortedUniqueElementsArray) { + _sortedUniqueElementsArray = sortedUniqueElementsArray; + return this; + } + + public Builder withCompressionType(ChunkCompressionType chunkCompressionType) { + _chunkCompressionType = chunkCompressionType; + return this; + } + + public Builder withBloomFilterConfig(BloomFilterConfig bloomFilterConfig) { + _bloomFilterConfig = bloomFilterConfig; + return this; + } + + public Builder withRangeIndexVersion(int rangeIndexVersion) { + _rangeIndexVersion = rangeIndexVersion; + return this; + } + + public IndexCreationContext build() { + return new IndexCreationContext(Objects.requireNonNull(_indexDir), + _columnProperties, _h3IndexConfig, _fstType, _lengthOfLongestEntry, + _maxNumberOfMultiValueElements, _maxRowLengthInBytes, + _sortedUniqueElementsArray, _onHeap, _chunkCompressionType, _bloomFilterConfig, + _rangeIndexVersion, + Objects.requireNonNull(_columnMetadata)); + } + } + + public static IndexCreationContext.Builder builder() { + return new Builder(); + } + + private final File _indexDir; + private final Map<String, Map<String, String>> _columnProperties; + private final FSTType _fstType; + private final H3IndexConfig _h3IndexConfig; + private final int _lengthOfLongestEntry; + private final int _maxNumberOfMultiValueElements; + private final int _maxRowLengthInBytes; + private final Object _sortedUniqueElementsArray; + private final boolean _onHeap; + private final ChunkCompressionType _chunkCompressionType; + public final BloomFilterConfig _bloomFilterConfig; + private final int _rangeIndexVersion; + private final ColumnMetadata _columnMetadata; + + public IndexCreationContext(File indexDir, @Nullable Map<String, Map<String, String>> columnProperties, + @Nullable H3IndexConfig h3IndexConfig, @Nullable FSTType fstType, int lengthOfLongestEntry, + int maxNumberOfMultiValueElements, int maxRowLengthInBytes, Object sortedUniqueElementsArray, boolean onHeap, + @Nullable ChunkCompressionType chunkCompressionType, @Nullable BloomFilterConfig bloomFilterConfig, + int rangeIndexVersion, ColumnMetadata columnMetadata) { + _indexDir = indexDir; + _columnProperties = columnProperties; + _fstType = fstType; + _h3IndexConfig = h3IndexConfig; + _lengthOfLongestEntry = lengthOfLongestEntry; + _maxNumberOfMultiValueElements = maxNumberOfMultiValueElements; + _maxRowLengthInBytes = maxRowLengthInBytes; + _sortedUniqueElementsArray = sortedUniqueElementsArray; + _onHeap = onHeap; + _chunkCompressionType = chunkCompressionType; + _bloomFilterConfig = bloomFilterConfig; + _rangeIndexVersion = rangeIndexVersion; + _columnMetadata = columnMetadata; + } + + public FieldSpec getFieldSpec() { + return _columnMetadata.getFieldSpec(); + } + + public File getIndexDir() { + return _indexDir; + } + + @Nullable + public Map<String, Map<String, String>> getColumnProperties() { + return _columnProperties; + } + + public boolean isOnHeap() { + return _onHeap; + } + + public int getLengthOfLongestEntry() { + return _lengthOfLongestEntry; + } + + public int getMaxNumberOfMultiValueElements() { + return _maxNumberOfMultiValueElements; + } + + public int getMaxRowLengthInBytes() { + return _maxRowLengthInBytes; + } + + public boolean isSorted() { + return _columnMetadata.isSorted(); + } + + public int getCardinality() { + return _columnMetadata.getCardinality(); + } + + public int getTotalNumberOfEntries() { + return _columnMetadata.getTotalNumberOfEntries(); + } + + public Object getSortedUniqueElementsArray() { + return _sortedUniqueElementsArray; + } + + public int getTotalDocs() { + return _columnMetadata.getTotalDocs(); + } + + public boolean isRawColumn() { Review comment: (nit) should we call it isDictionaryBased or hasDictionary() ? -- 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]
