siddharthteotia commented on a change in pull request #5774: URL: https://github.com/apache/incubator-pinot/pull/5774#discussion_r465796631
########## File path: pinot-controller/src/main/java/org/apache/pinot/controller/recommender/rules/impl/NoDictionaryOnHeapDictionaryJointRule.java ########## @@ -0,0 +1,245 @@ +/** + * 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.controller.recommender.rules.impl; + +import com.google.common.util.concurrent.AtomicDouble; +import java.util.HashSet; +import java.util.Set; +import org.apache.pinot.common.request.BrokerRequest; +import org.apache.pinot.core.query.request.context.ExpressionContext; +import org.apache.pinot.core.query.request.context.FilterContext; +import org.apache.pinot.core.query.request.context.QueryContext; +import org.apache.pinot.core.query.request.context.predicate.Predicate; +import org.apache.pinot.core.query.request.context.utils.BrokerRequestToQueryContextConverter; +import org.apache.pinot.core.requesthandler.BrokerRequestOptimizer; +import org.apache.pinot.core.requesthandler.PinotQueryParserFactory; +import org.apache.pinot.parsers.AbstractCompiler; +import org.apache.pinot.sql.parsers.SqlCompilationException; +import org.apache.pinot.controller.recommender.io.ConfigManager; +import org.apache.pinot.controller.recommender.io.InputManager; +import org.apache.pinot.controller.recommender.rules.AbstractRule; +import org.apache.pinot.controller.recommender.rules.io.params.NoDictionaryOnHeapDictionaryJointRuleParams; +import org.apache.pinot.controller.recommender.rules.utils.FixedLenBitset; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import static java.lang.Math.max; +import static java.lang.Math.min; +import static org.apache.pinot.controller.recommender.rules.io.params.RecommenderConstants.NoDictionaryOnHeapDictionaryJointRule.*; +import static org.apache.pinot.controller.recommender.rules.io.params.RecommenderConstants.REALTIME; + + +public class NoDictionaryOnHeapDictionaryJointRule extends AbstractRule { + private final Logger LOGGER = LoggerFactory.getLogger(NoDictionaryOnHeapDictionaryJointRule.class); + private final BrokerRequestOptimizer _brokerRequestOptimizer = new BrokerRequestOptimizer(); + private final NoDictionaryOnHeapDictionaryJointRuleParams _params; + + public NoDictionaryOnHeapDictionaryJointRule(InputManager inputManager, ConfigManager outputManager) { + super(inputManager, outputManager); + _params = inputManager.getNoDictionaryOnHeapDictionaryJointRuleParams(); + } + + @Override + public void run() { + LOGGER.info("Recommending no dictionary and on-heap dictionaries"); + + int numCols = _inputManager.getNumCols(); + double[] filterGroupByWeights = new double[numCols]; + double[] selectionWeights = new double[numCols]; + AtomicDouble totalWeight = new AtomicDouble(0); + + //**********No dictionary recommendation*******/ + Set<String> noDictCols = new HashSet<>(_inputManager.getColNameToIntMap().keySet()); + + //Exclude cols with index + noDictCols.removeAll(_outputManager.getIndexConfig().getInvertedIndexColumns()); + noDictCols.removeAll(_outputManager.getIndexConfig().getSortedColumn()); + // TODO: Remove this after range index is implemented for no-dictionary + noDictCols.removeAll(_outputManager.getIndexConfig().getRangeIndexColumns()); + LOGGER.debug("noDictCols {}", noDictCols); + //Find out columns used in filter&groupby and selection and corresponding frequencies + _inputManager.getQueryWeightMap().forEach((query, weight) -> { + parseQuery(query, weight, filterGroupByWeights, selectionWeights); + totalWeight.addAndGet(weight); + }); + + //Add dictionary on columns used in filter&groupby , with frequency > threshold + for (int i = 0; i < numCols; i++) { + double filterGroupByFreq = filterGroupByWeights[i] / totalWeight.get(); + if (filterGroupByFreq > _params.THRESHOLD_MIN_FILTER_FREQ_DICTIONARY) { + noDictCols.remove(_inputManager.intToColName(i)); + } + } + + LOGGER.debug("filterGroupByWeights {}, selectionWeights{}, totalWeight{} ", filterGroupByWeights, selectionWeights, + totalWeight); + LOGGER.debug("noDictCols {}", noDictCols); + + for (int i = 0; i < numCols; i++) { + // No dictionary on columns frequently used in selection Review comment: Might want to add comment about the experiment done during the design phase -- for a column heavily used in selection only (not part of filter or group by), making it no dictionary reduces the latency by 20% (I guess) since we avoid the 2 lookups. ---------------------------------------------------------------- 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