You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2020/08/06 15:16:23 UTC
[incubator-doris] branch master updated: [SQL] Support
approx_count_distinct rewrite to hll union in mv rewriter (#4239)
This is an automated email from the ASF dual-hosted git repository.
morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push:
new 4c05edd [SQL] Support approx_count_distinct rewrite to hll union in mv rewriter (#4239)
4c05edd is described below
commit 4c05eddc10b42712ed4614eaae0498c50019d49b
Author: EmmyMiao87 <52...@qq.com>
AuthorDate: Thu Aug 6 23:16:15 2020 +0800
[SQL] Support approx_count_distinct rewrite to hll union in mv rewriter (#4239)
The new function approx_count_distinct is the alias of function ndv.
So Doris also need to rewrite approx_count_distinct to hll function when it is possible to match the hll materialized view.
---
.../main/java/org/apache/doris/rewrite/mvrewrite/NDVToHll.java | 8 +++++---
.../org/apache/doris/planner/MaterializedViewFunctionTest.java | 9 +++++++++
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/NDVToHll.java b/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/NDVToHll.java
index e96abb4..a6ce08c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/NDVToHll.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/rewrite/mvrewrite/NDVToHll.java
@@ -36,13 +36,14 @@ import com.google.common.collect.Lists;
import java.util.List;
/**
- * For duplicate table, the ndv(k1) could be rewritten to hll_union_agg(mv_hll_union_k1) when bitmap
+ * For duplicate table, the ndv(k1) could be rewritten to hll_union_agg(mv_hll_union_k1) when hll
* mv exists.
* For example:
* Table: (k1 int, k2 int)
* MV: (k1 int, mv_hll_union_k2 hll hll_union)
* mv_hll_union_k2 = hll_hash(k2)
- * Query: select k1, count(distinct k2) from table group by k1
+ * Query: select k1, ndv(k2) from table group by k1
+ * or select k1, approx_count_distinct(k2) from table group by k1
* Rewritten query: select k1, hll_union_agg(mv_hll_union_k2) from table group by k1
*/
public class NDVToHll implements ExprRewriteRule{
@@ -55,7 +56,8 @@ public class NDVToHll implements ExprRewriteRule{
return expr;
}
FunctionCallExpr fnExpr = (FunctionCallExpr) expr;
- if (!fnExpr.getFnName().getFunction().equalsIgnoreCase("ndv")) {
+ if (!fnExpr.getFnName().getFunction().equalsIgnoreCase("ndv")
+ && !fnExpr.getFnName().getFunction().equalsIgnoreCase("approx_count_distinct")) {
return expr;
}
if (fnExpr.getChildren().size() != 1 || !(fnExpr.getChild(0) instanceof SlotRef)) {
diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java
index 49ec316..173ca92 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/MaterializedViewFunctionTest.java
@@ -758,6 +758,15 @@ public class MaterializedViewFunctionTest {
}
@Test
+ public void testApproxCountDistinctToHll() throws Exception {
+ String createUserTagMVSql = "create materialized view " + USER_TAG_MV_NAME + " as select user_id, " +
+ "`" + FunctionSet.HLL_UNION + "`(" + FunctionSet.HLL_HASH + "(tag_id)) from " + USER_TAG_TABLE_NAME + " group by user_id;";
+ dorisAssert.withMaterializedView(createUserTagMVSql);
+ String query = "select approx_count_distinct(tag_id) from " + USER_TAG_TABLE_NAME + ";";
+ dorisAssert.query(query).explainContains(USER_TAG_MV_NAME, "hll_union_agg");
+ }
+
+ @Test
public void testHLLUnionFamilyRewrite() throws Exception {
String createUserTagMVSql = "create materialized view " + USER_TAG_MV_NAME + " as select user_id, " +
"`" + FunctionSet.HLL_UNION + "`(" + FunctionSet.HLL_HASH + "(tag_id)) from " + USER_TAG_TABLE_NAME + " group by user_id;";
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org