Repository: kylin Updated Branches: refs/heads/master 14dd92e00 -> 9265e150d
KYLIN-3055 Fix NPE for intersect_count query Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/9265e150 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/9265e150 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/9265e150 Branch: refs/heads/master Commit: 9265e150d80519d3e4f532c5f106e6718543daba Parents: 14dd92e Author: yuchuqian <y...@meitu.com> Authored: Mon Dec 4 14:30:28 2017 +0800 Committer: kangkaisen <kangkai...@meituan.com> Committed: Wed Dec 6 20:09:44 2017 +0800 ---------------------------------------------------------------------- .../gtrecord/GTCubeStorageQueryBase.java | 11 ++++++-- .../query/sql_intersect_count/query01.sql | 27 ++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/9265e150/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java ---------------------------------------------------------------------- diff --git a/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java b/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java index e9c6885..024990f 100644 --- a/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java +++ b/core-storage/src/main/java/org/apache/kylin/storage/gtrecord/GTCubeStorageQueryBase.java @@ -39,6 +39,7 @@ import org.apache.kylin.cube.model.RowKeyColDesc; import org.apache.kylin.dict.lookup.LookupStringTable; import org.apache.kylin.gridtable.StorageLimitLevel; import org.apache.kylin.measure.MeasureType; +import org.apache.kylin.measure.bitmap.BitmapMeasureType; import org.apache.kylin.metadata.filter.CaseTupleFilter; import org.apache.kylin.metadata.filter.ColumnTupleFilter; import org.apache.kylin.metadata.filter.CompareTupleFilter; @@ -143,7 +144,7 @@ public abstract class GTCubeStorageQueryBase implements IStorageQuery { // exactAggregation mean: needn't aggregation at storage and query engine both. boolean exactAggregation = isExactAggregation(context, cuboid, groups, otherDimsD, singleValuesD, - derivedPostAggregation, sqlDigest.aggregations); + derivedPostAggregation, sqlDigest.aggregations, sqlDigest.aggrSqlCalls); context.setExactAggregation(exactAggregation); // replace derived columns in filter with host columns; columns on loosened condition must be added to group by @@ -518,7 +519,7 @@ public abstract class GTCubeStorageQueryBase implements IStorageQuery { private boolean isExactAggregation(StorageContext context, Cuboid cuboid, Collection<TblColRef> groups, Set<TblColRef> othersD, Set<TblColRef> singleValuesD, Set<TblColRef> derivedPostAggregation, - Collection<FunctionDesc> functionDescs) { + Collection<FunctionDesc> functionDescs, List<SQLDigest.SQLCall> aggrSQLCalls) { if (context.isNeedStorageAggregation()) { logger.info("exactAggregation is false because need storage aggregation"); return false; @@ -550,6 +551,12 @@ public abstract class GTCubeStorageQueryBase implements IStorageQuery { return false; } } + for (SQLDigest.SQLCall aggrSQLCall : aggrSQLCalls) { + if (aggrSQLCall.function.equals(BitmapMeasureType.FUNC_INTERSECT_COUNT_DISTINCT)) { + logger.info("exactAggregation is false because has INTERSECT_COUNT"); + return false; + } + } // for partitioned cube, the partition column must belong to group by or has single value PartitionDesc partDesc = cuboid.getCubeDesc().getModel().getPartitionDesc(); http://git-wip-us.apache.org/repos/asf/kylin/blob/9265e150/kylin-it/src/test/resources/query/sql_intersect_count/query01.sql ---------------------------------------------------------------------- diff --git a/kylin-it/src/test/resources/query/sql_intersect_count/query01.sql b/kylin-it/src/test/resources/query/sql_intersect_count/query01.sql new file mode 100644 index 0000000..7fd5ca2 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_intersect_count/query01.sql @@ -0,0 +1,27 @@ +-- +-- 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. +-- +select CAL_DT, +intersect_count(TEST_COUNT_DISTINCT_BITMAP, CAL_DT, array[date'2012-01-01']) as first_day, +intersect_count(TEST_COUNT_DISTINCT_BITMAP, CAL_DT, array[date'2012-01-02']) as second_day, +intersect_count(TEST_COUNT_DISTINCT_BITMAP, CAL_DT, array[date'2012-01-03']) as third_day, +intersect_count(TEST_COUNT_DISTINCT_BITMAP, CAL_DT, array[date'2012-01-01',date'2012-01-02']) as retention_oneday, +intersect_count(TEST_COUNT_DISTINCT_BITMAP, CAL_DT, array[date'2012-01-01',date'2012-01-02',date'2012-01-03']) as retention_twoday +from test_kylin_fact +where CAL_DT in (date'2012-01-01',date'2012-01-02',date'2012-01-03') +group by CAL_DT +