KYLIN-2098 TopN support query UHC column without sorting by sum value Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/7b33d0a4 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/7b33d0a4 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/7b33d0a4
Branch: refs/heads/yang21-hbase1.x Commit: 7b33d0a490b2efa6a8206614c1987872112c0f2b Parents: 34b6419 Author: shaofengshi <shaofeng...@apache.org> Authored: Mon Oct 17 13:51:05 2016 +0800 Committer: shaofengshi <shaofeng...@apache.org> Committed: Thu Oct 20 14:36:50 2016 +0800 ---------------------------------------------------------------------- .../kylin/measure/topn/TopNMeasureType.java | 55 +++++++++++++------- 1 file changed, 35 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/7b33d0a4/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java ---------------------------------------------------------------------- diff --git a/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java b/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java index b0d469d..39549ee 100644 --- a/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java +++ b/core-metadata/src/main/java/org/apache/kylin/measure/topn/TopNMeasureType.java @@ -231,34 +231,49 @@ public class TopNMeasureType extends MeasureType<TopNCounter<ByteArray>> { // TopN measure can (and only can) provide one numeric measure and one literal dimension // e.g. select seller, sum(gmv) from ... group by seller order by 2 desc limit 100 - // check digest requires only one measure - if (digest.aggregations.size() != 1) - return null; - - // the measure function must be SUM - FunctionDesc onlyFunction = digest.aggregations.iterator().next(); - if (isTopNCompatibleSum(topN.getFunction(), onlyFunction) == false) - return null; - List<TblColRef> literalCol = getTopNLiteralColumn(topN.getFunction()); + for (TblColRef colRef : literalCol) { + if (digest.filterColumns.contains(colRef) == true) { + // doesn't allow filtering by topn literal column + return null; + } + } + if (unmatchedDimensions.containsAll(literalCol) == false) return null; if (digest.groupbyColumns.containsAll(literalCol) == false) return null; - for (TblColRef colRef : literalCol) { - if (digest.filterColumns.contains(colRef) == true) { + // check digest requires only one measure + if (digest.aggregations.size() == 1) { + + // the measure function must be SUM + FunctionDesc onlyFunction = digest.aggregations.iterator().next(); + if (isTopNCompatibleSum(topN.getFunction(), onlyFunction) == false) return null; - } + + unmatchedDimensions.removeAll(literalCol); + unmatchedAggregations.remove(onlyFunction); + return new CapabilityInfluence() { + @Override + public double suggestCostMultiplier() { + return 0.3; // make sure TopN get ahead of other matched realizations + } + }; } - unmatchedDimensions.removeAll(literalCol); - unmatchedAggregations.remove(onlyFunction); - return new CapabilityInfluence() { - @Override - public double suggestCostMultiplier() { - return 0.3; // make sure TopN get ahead of other matched realizations - } - }; + + if (digest.aggregations.size() == 0 ) { + // directly query the UHC column without sorting + unmatchedDimensions.removeAll(literalCol); + return new CapabilityInfluence() { + @Override + public double suggestCostMultiplier() { + return 2.0; // topn can answer but with a higher cost + } + }; + } + + return null; } private boolean isTopNCompatibleSum(FunctionDesc topN, FunctionDesc sum) {