Jackie-Jiang commented on a change in pull request #6466: URL: https://github.com/apache/incubator-pinot/pull/6466#discussion_r574933740
########## File path: pinot-core/src/main/java/org/apache/pinot/core/indexsegment/immutable/ImmutableSegmentLoader.java ########## @@ -105,32 +105,34 @@ public static ImmutableSegment load(File indexDir, IndexLoadingConfig indexLoadi // Load the segment ReadMode readMode = indexLoadingConfig.getReadMode(); SegmentDirectory segmentDirectory = SegmentDirectory.createFromLocalFS(indexDir, segmentMetadata, readMode); - SegmentDirectory.Reader segmentReader = segmentDirectory.createReader(); Map<String, ColumnIndexContainer> indexContainerMap = new HashMap<>(); - for (Map.Entry<String, ColumnMetadata> entry : segmentMetadata.getColumnMetadataMap().entrySet()) { - indexContainerMap.put(entry.getKey(), - new PhysicalColumnIndexContainer(segmentReader, entry.getValue(), indexLoadingConfig, indexDir)); - } + StarTreeIndexContainer starTreeIndexContainer = null; - // Instantiate virtual columns - Schema segmentSchema = segmentMetadata.getSchema(); - VirtualColumnProviderFactory.addBuiltInVirtualColumnsToSegmentSchema(segmentSchema, segmentName); - for (FieldSpec fieldSpec : segmentSchema.getAllFieldSpecs()) { - if (fieldSpec.isVirtualColumn()) { - String columnName = fieldSpec.getName(); - VirtualColumnContext context = new VirtualColumnContext(fieldSpec, segmentMetadata.getTotalDocs()); - VirtualColumnProvider provider = VirtualColumnProviderFactory.buildProvider(context); - indexContainerMap.put(columnName, provider.buildColumnIndexContainer(context)); - segmentMetadata.getColumnMetadataMap().put(columnName, provider.buildMetadata(context)); + if (segmentMetadata.getTotalDocs() > 0) { Review comment: Special case empty segment in line 105 and directly return, no need to change the existing code ```suggestion if (segmentMetadata.getTotalDocs() == 0) { return new EmptyIndexSegment(segmentMetadata); } ``` ########## File path: pinot-core/src/main/java/org/apache/pinot/core/indexsegment/immutable/ImmutableSegmentImpl.java ########## @@ -115,7 +116,11 @@ public DataSource getDataSource(String column) { ColumnMetadata columnMetadata = _segmentMetadata.getColumnMetadataFor(column); Preconditions.checkNotNull(columnMetadata, "ColumnMetadata for " + column + " should not be null. " + "Potentially invalid column name specified."); - return new ImmutableDataSource(columnMetadata, _indexContainerMap.get(column)); + if (_indexContainerMap.containsKey(column)) { Review comment: This is not needed ########## File path: pinot-core/src/main/java/org/apache/pinot/core/indexsegment/immutable/EmptyIndexSegment.java ########## @@ -0,0 +1,130 @@ +/** + * 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.core.indexsegment.immutable; + +import com.google.common.base.Preconditions; +import java.util.List; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.pinot.core.common.DataSource; +import org.apache.pinot.core.segment.index.datasource.EmptyDataSource; +import org.apache.pinot.core.segment.index.metadata.ColumnMetadata; +import org.apache.pinot.core.segment.index.metadata.SegmentMetadataImpl; +import org.apache.pinot.core.segment.index.readers.Dictionary; +import org.apache.pinot.core.segment.index.readers.ForwardIndexReader; +import org.apache.pinot.core.segment.index.readers.InvertedIndexReader; +import org.apache.pinot.core.segment.index.readers.ValidDocIndexReader; +import org.apache.pinot.core.segment.store.SegmentDirectory; +import org.apache.pinot.core.startree.v2.StarTreeV2; +import org.apache.pinot.spi.data.readers.GenericRow; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Immutable segment impl for empty segment + * Such an IndexSegment contains only the metadata, and no indexes + */ +public class EmptyIndexSegment implements ImmutableSegment { + private static final Logger LOGGER = LoggerFactory.getLogger(EmptyIndexSegment.class); + + private final SegmentDirectory _segmentDirectory; + private final SegmentMetadataImpl _segmentMetadata; + + public EmptyIndexSegment(SegmentDirectory segmentDirectory, SegmentMetadataImpl segmentMetadata) { Review comment: No need to pass in the segmentDirectory. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org