-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
8 changed files
with
334 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...ller/src/main/java/org/apache/pinot/controller/recommender/rules/impl/RangeIndexRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* 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.info("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; | ||
} | ||
|
||
return parsePredicateList(queryContext.getFilter()); | ||
} | ||
|
||
/** | ||
* As cardinality does not matter, AND and OR columns will be considered | ||
* @param filterContext filterContext | ||
* @return FixedLenBitset for range predicates in this query | ||
*/ | ||
private FixedLenBitset parsePredicateList(FilterContext filterContext) { | ||
FilterContext.Type type = filterContext.getType(); | ||
FixedLenBitset ret = MUTABLE_EMPTY_SET(); | ||
if (type == FilterContext.Type.AND || type == FilterContext.Type.OR) { | ||
for (int i = 0; i < filterContext.getChildren().size(); i++) { | ||
FixedLenBitset childResult = parsePredicateList(filterContext.getChildren().get(i)); | ||
ret.union(childResult); | ||
} | ||
} else { | ||
ExpressionContext lhs = filterContext.getPredicate().getLhs(); | ||
String colName = lhs.toString(); | ||
if (lhs.getType() == ExpressionContext.Type.FUNCTION) { | ||
LOGGER.trace("Skipping the function {}", colName); | ||
} else if (filterContext.getPredicate().getType() == Predicate.Type.RANGE) { | ||
ret.add(_input.colNameToInt(colName)); | ||
} | ||
} | ||
return ret; | ||
} | ||
|
||
private FixedLenBitset MUTABLE_EMPTY_SET() { | ||
return new FixedLenBitset(_input.getNumCols()); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...in/java/org/apache/pinot/controller/recommender/rules/io/params/RangeIndexRuleParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* 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.io.params; | ||
|
||
import com.fasterxml.jackson.annotation.JsonSetter; | ||
import com.fasterxml.jackson.annotation.Nulls; | ||
|
||
/** | ||
* Thresholds and parameters used in @RangeIndexRule | ||
*/ | ||
public class RangeIndexRuleParams { | ||
public Double THRESHOLD_MIN_PERCENT_RANGE_INDEX = RecommenderConstants.RangeIndexRule.DEFAULT_THRESHOLD_MIN_PERCENT_RANGE_INDEX; | ||
|
||
public Double getTHRESHOLD_MIN_PERCENT_RANGE_INDEX() { | ||
return THRESHOLD_MIN_PERCENT_RANGE_INDEX; | ||
} | ||
|
||
@JsonSetter(value = "THRESHOLD_MIN_PERCENT_RANGE_INDEX", nulls = Nulls.SKIP) | ||
public void setTHRESHOLD_MIN_PERCENT_RANGE_INDEX(Double THRESHOLD_MIN_PERCENT_RANGE_INDEX) { | ||
this.THRESHOLD_MIN_PERCENT_RANGE_INDEX = THRESHOLD_MIN_PERCENT_RANGE_INDEX; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.