You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2021/06/18 22:49:37 UTC

[GitHub] [incubator-pinot] jackjlli commented on a change in pull request #7063: Add support for range index rule recommendation(#7034)

jackjlli commented on a change in pull request #7063:
URL: https://github.com/apache/incubator-pinot/pull/7063#discussion_r654704283



##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/recommender/rules/impl/RangeIndexRule.java
##########
@@ -0,0 +1,117 @@
+/**
+ * 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 org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.FilterContext;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+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.RangeIndexRuleParams;
+import org.apache.pinot.controller.recommender.rules.utils.FixedLenBitset;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Create range-index for columns used in <, > and between predicate
+ * Skip the inverted and sorted index columns if recommended
+ */
+public class RangeIndexRule extends AbstractRule {
+  private final Logger LOGGER = LoggerFactory.getLogger(RangeIndexRule.class);
+  private final RangeIndexRuleParams _params;
+
+  public RangeIndexRule(InputManager input, ConfigManager output) {
+    super(input, output);
+    _params = input.getRangeIndexRuleParams();
+  }
+
+  @Override
+  public void run() {
+    int numCols = _input.getNumCols();
+    double[] weights = new double[numCols];
+    AtomicDouble totalWeight = new AtomicDouble(0);
+
+    // For each query, find out the range columns
+    // and accumulate the (weighted) frequencies
+    _input.getParsedQueries().forEach(query -> {
+      Double weight = _input.getQueryWeight(query);
+      totalWeight.addAndGet(weight);
+      FixedLenBitset fixedLenBitset = parseQuery(_input.getQueryContext(query));
+      LOGGER.debug("fixedLenBitset {}", fixedLenBitset);
+      for (Integer i : fixedLenBitset.getOffsets()) {
+        weights[i] += weight;
+      }
+    });
+    LOGGER.debug("Weight: {}, Total {}", weights, totalWeight);
+
+    for (int i = 0; i < numCols; i++) {
+      String colName = _input.intToColName(i);
+      // This checks if column is not already recommended for inverted index or sorted index
+      // As currently, only numeric columns are selected in range index creation, we will skip non numeric columns
+      if (((weights[i] / totalWeight.get()) > _params.THRESHOLD_MIN_PERCENT_RANGE_INDEX) &&
+          !_output.getIndexConfig().getSortedColumn().equals(colName) &&
+          !_output.getIndexConfig().getInvertedIndexColumns().contains(colName) &&
+          _input.getFieldType(colName).isNumeric()) {
+        _output.getIndexConfig().getRangeIndexColumns().add(colName);
+      }
+    }
+  }
+
+  public FixedLenBitset parseQuery(QueryContext queryContext) {
+    if (queryContext.getFilter() == null) {
+      return FixedLenBitset.IMMUTABLE_EMPTY_SET;
+    }
+
+    LOGGER.trace("Parsing Where Clause: {}", queryContext.getFilter().toString());

Review comment:
       We might not need log in trace level.

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/recommender/rules/impl/RangeIndexRule.java
##########
@@ -0,0 +1,117 @@
+/**
+ * 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 org.apache.pinot.common.request.context.ExpressionContext;
+import org.apache.pinot.common.request.context.FilterContext;
+import org.apache.pinot.common.request.context.predicate.Predicate;
+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.RangeIndexRuleParams;
+import org.apache.pinot.controller.recommender.rules.utils.FixedLenBitset;
+import org.apache.pinot.core.query.request.context.QueryContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Create range-index for columns used in <, > and between predicate
+ * Skip the inverted and sorted index columns if recommended
+ */
+public class RangeIndexRule extends AbstractRule {
+  private final Logger LOGGER = LoggerFactory.getLogger(RangeIndexRule.class);
+  private final RangeIndexRuleParams _params;
+
+  public RangeIndexRule(InputManager input, ConfigManager output) {
+    super(input, output);
+    _params = input.getRangeIndexRuleParams();
+  }
+
+  @Override
+  public void run() {
+    int numCols = _input.getNumCols();
+    double[] weights = new double[numCols];
+    AtomicDouble totalWeight = new AtomicDouble(0);
+
+    // For each query, find out the range columns
+    // and accumulate the (weighted) frequencies
+    _input.getParsedQueries().forEach(query -> {
+      Double weight = _input.getQueryWeight(query);
+      totalWeight.addAndGet(weight);
+      FixedLenBitset fixedLenBitset = parseQuery(_input.getQueryContext(query));
+      LOGGER.debug("fixedLenBitset {}", fixedLenBitset);
+      for (Integer i : fixedLenBitset.getOffsets()) {
+        weights[i] += weight;
+      }
+    });
+    LOGGER.debug("Weight: {}, Total {}", weights, totalWeight);

Review comment:
       Set it to `info` level since it's printed only once?

##########
File path: pinot-controller/src/main/java/org/apache/pinot/controller/recommender/rules/impl/NoDictionaryOnHeapDictionaryJointRule.java
##########
@@ -85,7 +85,7 @@ public void run() {
     noDictCols.removeAll(_output.getIndexConfig().getInvertedIndexColumns());
     noDictCols.remove(_output.getIndexConfig().getSortedColumn());
     noDictCols.removeAll(_output.getIndexConfig()
-        .getRangeIndexColumns()); // TODO: Remove this after range index is implemented for no-dictionary
+        .getRangeIndexColumns());

Review comment:
       nit: merge this line to the previous line?




-- 
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org