Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite count(distinct if(bool, bitmap, null)) to bitmap_union_count #4201

Merged
merged 2 commits into from
Aug 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package org.apache.doris.planner;

import com.google.common.collect.Lists;
import org.apache.doris.analysis.CreateDbStmt;
import org.apache.doris.analysis.CreateTableStmt;
import org.apache.doris.analysis.DropDbStmt;
Expand All @@ -41,6 +40,8 @@
import org.apache.doris.qe.QueryState.MysqlStateType;
import org.apache.doris.utframe.UtFrameUtils;

import com.google.common.collect.Lists;

import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import org.junit.Assert;
Expand Down Expand Up @@ -136,7 +137,8 @@ public static void beforeClass() throws Exception {

createTable("CREATE TABLE test.bitmap_table_2 (\n" +
" `id` int(11) NULL COMMENT \"\",\n" +
" `id2` bitmap bitmap_union NULL\n" +
" `id2` bitmap bitmap_union NULL,\n" +
" `id3` bitmap bitmap_union NULL\n" +
") ENGINE=OLAP\n" +
"AGGREGATE KEY(`id`)\n" +
"DISTRIBUTED BY HASH(`id`) BUCKETS 1\n" +
Expand Down Expand Up @@ -530,6 +532,18 @@ public void testCountDistinctRewrite() throws Exception {
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql);
Assert.assertTrue(explainString.contains("bitmap_union_count"));

sql = "select count(distinct if(id = 1, id2, null)) from test.bitmap_table";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql);
Assert.assertTrue(explainString.contains("bitmap_union_count"));

sql = "select count(distinct ifnull(id2, id3)) from test.bitmap_table_2";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql);
Assert.assertTrue(explainString.contains("bitmap_union_count"));

sql = "select count(distinct coalesce(id2, id3)) from test.bitmap_table_2";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql);
Assert.assertTrue(explainString.contains("bitmap_union_count"));

ConnectContext.get().getSessionVariable().setRewriteCountDistinct(false);
sql = "select count(distinct id2) from test.bitmap_table";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "explain " + sql);
Expand Down
3 changes: 3 additions & 0 deletions gensrc/script/doris_builtins_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@
[['if'], 'DATE', ['BOOLEAN', 'DATE', 'DATE'], ''],
[['if'], 'DECIMAL', ['BOOLEAN', 'DECIMAL', 'DECIMAL'], ''],
[['if'], 'DECIMALV2', ['BOOLEAN', 'DECIMALV2', 'DECIMALV2'], ''],
[['if'], 'BITMAP', ['BOOLEAN', 'BITMAP', 'BITMAP'], ''],
# The priority of varchar should be lower than decimal in IS_SUPERTYPE_OF mode.
[['if'], 'VARCHAR', ['BOOLEAN', 'VARCHAR', 'VARCHAR'], ''],

Expand Down Expand Up @@ -493,6 +494,7 @@
[['ifnull'], 'DATETIME', ['DATETIME', 'DATE'], ''],
[['ifnull'], 'DECIMAL', ['DECIMAL', 'DECIMAL'], ''],
[['ifnull'], 'DECIMALV2', ['DECIMALV2', 'DECIMALV2'], ''],
[['ifnull'], 'BITMAP', ['BITMAP', 'BITMAP'], ''],
# The priority of varchar should be lower than decimal in IS_SUPERTYPE_OF mode.
[['ifnull'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], ''],

Expand All @@ -508,6 +510,7 @@
[['coalesce'], 'DATE', ['DATE', '...'], ''],
[['coalesce'], 'DECIMAL', ['DECIMAL', '...'], ''],
[['coalesce'], 'DECIMALV2', ['DECIMALV2', '...'], ''],
[['coalesce'], 'BITMAP', ['BITMAP', '...'], ''],
# The priority of varchar should be lower than decimal in IS_SUPERTYPE_OF mode.
[['coalesce'], 'VARCHAR', ['VARCHAR', '...'], ''],

Expand Down