VenuReddy2103 commented on a change in pull request #4110: URL: https://github.com/apache/carbondata/pull/4110#discussion_r609298135
########## File path: integration/spark/src/main/scala/org/apache/carbondata/index/secondary/SecondaryIndex.java ########## @@ -0,0 +1,128 @@ +/* + * 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.carbondata.index.secondary; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.carbondata.common.logging.LogServiceFactory; +import org.apache.carbondata.core.datastore.block.SegmentProperties; +import org.apache.carbondata.core.index.IndexUtil; +import org.apache.carbondata.core.index.dev.IndexModel; +import org.apache.carbondata.core.index.dev.cgindex.CoarseGrainIndex; +import org.apache.carbondata.core.indexstore.Blocklet; +import org.apache.carbondata.core.metadata.schema.table.CarbonTable; +import org.apache.carbondata.core.scan.expression.Expression; +import org.apache.carbondata.core.scan.filter.executer.FilterExecutor; +import org.apache.carbondata.core.scan.filter.resolver.FilterResolverIntf; +import org.apache.carbondata.index.secondary.SecondaryIndexModel.PositionReferenceInfo; + +import org.apache.log4j.Logger; + +import static org.apache.carbondata.core.util.path.CarbonTablePath.BATCH_PREFIX; + +/** + * Secondary Index to prune at blocklet level. + */ +public class SecondaryIndex extends CoarseGrainIndex { + private static final Logger LOGGER = + LogServiceFactory.getLogService(SecondaryIndex.class.getName()); + String indexName; + String currentSegmentId; + List<String> validSegmentIds; + PositionReferenceInfo positionReferenceInfo; + + @Override + public void init(IndexModel indexModel) { + assert (indexModel instanceof SecondaryIndexModel); + SecondaryIndexModel model = (SecondaryIndexModel) indexModel; + indexName = model.indexName; + currentSegmentId = model.currentSegmentId; + validSegmentIds = model.validSegmentIds; + positionReferenceInfo = model.positionReferenceInfo; + } + + private Set<String> getPositionReferences(String databaseName, String indexName, + Expression expression) { + synchronized (positionReferenceInfo) { + /* If the position references are not obtained yet(i.e., prune happening for the first valid + segment), then get them from the given index table with the given filter from all the valid + segments at once and store them as map of segmentId to set of position references in that + particular segment. Upon the subsequent prune for other segments, return the position + references for the respective segment from the map directly */ + if (!positionReferenceInfo.fetched) { Review comment: They do not share the same position reference across queries. Have added more comments to `PositionReferenceInfo` class now. One instance of `PositionReferenceInfo` is shared across all the `SecondaryIndex` instances for the particular query pruning with the given index filter. This ensures to run a single sql query to get position references from the valid segments of the given secondary index table with given index filter and populate them in map. First secondary index segment prune in the query will run the sql query for position references and store them in map. And subsequent segments prune in the same query can avoid the individual sql for position references within the respective segment and return position references from the map directly. -- 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: [email protected]
