You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/12/06 11:59:29 UTC

[GitHub] [doris] wangshuo128 opened a new pull request, #14863: [feature](Nereids) Support bitmap for materialized index.

wangshuo128 opened a new pull request, #14863:
URL: https://github.com/apache/doris/pull/14863

   # Proposed changes
   
   Not ready to review...
   
   ## Problem summary
   
   todo...
   
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: 
       - [ ] Yes
       - [ ] No
       - [ ] I don't know
   2. Has unit tests been added:
       - [ ] Yes
       - [ ] No
       - [ ] No Need
   3. Has document been added or modified:
       - [ ] Yes
       - [ ] No
       - [ ] No Need
   4. Does it need to update dependencies:
       - [ ] Yes
       - [ ] No
   5. Are there any changes that cannot be rolled back:
       - [ ] Yes (If Yes, please explain WHY)
       - [ ] No
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc...
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] 924060929 commented on a diff in pull request #14863: [Feature](Nereids) Support bitmap for materialized index.

Posted by GitBox <gi...@apache.org>.
924060929 commented on code in PR #14863:
URL: https://github.com/apache/doris/pull/14863#discussion_r1052900899


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/CountDistinctRewrite.java:
##########
@@ -0,0 +1,73 @@
+// 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.doris.nereids.rules.rewrite.logical;
+
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapUnionCount;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
+import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * Rewrite count distinct for bitmap and hll type value.
+ * <p>
+ * count(distinct bitmap_col) -> bitmap_union_count(bitmap col)
+ * todo: add support for HLL type.
+ */
+public class CountDistinctRewrite extends OneRewriteRuleFactory {
+    @Override
+    public Rule build() {
+        return logicalAggregate().then(agg -> {
+            List<NamedExpression> output = agg.getOutputExpressions()
+                    .stream()
+                    .map(CountDistinctRewriter::rewrite)
+                    .map(NamedExpression.class::cast)
+                    .collect(ImmutableList.toImmutableList());
+            return new LogicalAggregate<>(agg.getGroupByExpressions(), output,
+                    agg.isDisassembled(), agg.isNormalized(),
+                    agg.isFinalPhase(), agg.getAggPhase(), agg.getSourceRepeat(), agg.child());
+        }).toRule(RuleType.COUNT_DISTINCT_REWRITE);
+    }
+
+    private static class CountDistinctRewriter extends DefaultExpressionRewriter<Void> {
+        private static final CountDistinctRewriter INSTANCE = new CountDistinctRewriter();
+
+        public static Expression rewrite(Expression expr) {
+            return expr.accept(INSTANCE, null);
+        }
+
+        @Override
+        public Expression visitCount(Count count, Void context) {
+            if (count.isDistinct()) {
+                Expression child = count.child(0);

Review Comment:
   count distinct can support multi columns, like `count(distinct id, value)`, so you should check the arity



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/CountDistinctRewrite.java:
##########
@@ -0,0 +1,73 @@
+// 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.doris.nereids.rules.rewrite.logical;
+
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapUnionCount;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
+import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * Rewrite count distinct for bitmap and hll type value.
+ * <p>
+ * count(distinct bitmap_col) -> bitmap_union_count(bitmap col)
+ * todo: add support for HLL type.
+ */
+public class CountDistinctRewrite extends OneRewriteRuleFactory {
+    @Override
+    public Rule build() {
+        return logicalAggregate().then(agg -> {
+            List<NamedExpression> output = agg.getOutputExpressions()
+                    .stream()
+                    .map(CountDistinctRewriter::rewrite)
+                    .map(NamedExpression.class::cast)
+                    .collect(ImmutableList.toImmutableList());
+            return new LogicalAggregate<>(agg.getGroupByExpressions(), output,
+                    agg.isDisassembled(), agg.isNormalized(),
+                    agg.isFinalPhase(), agg.getAggPhase(), agg.getSourceRepeat(), agg.child());
+        }).toRule(RuleType.COUNT_DISTINCT_REWRITE);
+    }
+
+    private static class CountDistinctRewriter extends DefaultExpressionRewriter<Void> {

Review Comment:
   a shorter rewriter:
   ```java
   ExpressionUtils.rewriteDownShortCircuit(agg.getOutputExpressions(), expr -> {
       if (expr instanceof Count && expr.arity() == 1 && ((Count) expr).isDistinct()
               && expr.child(0).getDataType().isBitmapType()) {
           return new BitmapUnionCount(expr.child(0));
       }
       return expr;
   })
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/CountDistinctRewrite.java:
##########
@@ -0,0 +1,73 @@
+// 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.doris.nereids.rules.rewrite.logical;
+
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.rules.rewrite.OneRewriteRuleFactory;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.functions.agg.BitmapUnionCount;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
+import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * Rewrite count distinct for bitmap and hll type value.
+ * <p>
+ * count(distinct bitmap_col) -> bitmap_union_count(bitmap col)
+ * todo: add support for HLL type.
+ */
+public class CountDistinctRewrite extends OneRewriteRuleFactory {
+    @Override
+    public Rule build() {
+        return logicalAggregate().then(agg -> {
+            List<NamedExpression> output = agg.getOutputExpressions()
+                    .stream()
+                    .map(CountDistinctRewriter::rewrite)
+                    .map(NamedExpression.class::cast)
+                    .collect(ImmutableList.toImmutableList());
+            return new LogicalAggregate<>(agg.getGroupByExpressions(), output,
+                    agg.isDisassembled(), agg.isNormalized(),
+                    agg.isFinalPhase(), agg.getAggPhase(), agg.getSourceRepeat(), agg.child());

Review Comment:
   why not invoke `agg.withAggOutput(output)`?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Command.java:
##########
@@ -83,6 +83,11 @@ default List<Slot> getOutput() {
         throw new RuntimeException("Command do not implement getOutput");
     }
 
+    @Override
+    default List<Slot> getNonUserVisibleOutput() {
+        throw new RuntimeException("Command do not implement getNonUserVisibleOutput");

Review Comment:
   why not supply an empty list?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/ExpressionUtils.java:
##########
@@ -234,12 +235,20 @@ public static Slot selectMinimumColumn(List<Slot> slots) {
      *         Otherwise, return empty optional result.
      */
     public static Optional<ExprId> isSlotOrCastOnSlot(Expression expr) {
+        return extractSlotOnCastOnSlot(expr).map(Slot::getExprId);
+    }
+
+    /**
+     * Check whether the input expression is a {@link org.apache.doris.nereids.trees.expressions.Slot}
+     * or at least one {@link Cast} on a {@link org.apache.doris.nereids.trees.expressions.Slot}
+     */
+    public static Optional<Slot> extractSlotOnCastOnSlot(Expression expr) {

Review Comment:
   ```suggestion
       public static Optional<Slot> extractSlotOrCastOnSlot(Expression expr) {
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] hello-stephen commented on pull request #14863: [Feature](Nereids) Support bitmap for materialized index.

Posted by GitBox <gi...@apache.org>.
hello-stephen commented on PR #14863:
URL: https://github.com/apache/doris/pull/14863#issuecomment-1339476071

   TeamCity pipeline, clickbench performance test result:
    the sum of best hot time: 34.69 seconds
    load time: 429 seconds
    storage size: 17123356335 Bytes
    https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/tmp/20221206143158_clickbench_pr_58822.html


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] 924060929 merged pull request #14863: [Feature](Nereids) Support bitmap for materialized index.

Posted by GitBox <gi...@apache.org>.
924060929 merged PR #14863:
URL: https://github.com/apache/doris/pull/14863


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [doris] wangshuo128 commented on a diff in pull request #14863: [Feature](Nereids) Support bitmap for materialized index.

Posted by GitBox <gi...@apache.org>.
wangshuo128 commented on code in PR #14863:
URL: https://github.com/apache/doris/pull/14863#discussion_r1053958360


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Command.java:
##########
@@ -83,6 +83,11 @@ default List<Slot> getOutput() {
         throw new RuntimeException("Command do not implement getOutput");
     }
 
+    @Override
+    default List<Slot> getNonUserVisibleOutput() {
+        throw new RuntimeException("Command do not implement getNonUserVisibleOutput");

Review Comment:
    I think both choices are Ok. Just keep consistent with `Command.getOutput`.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/Command.java:
##########
@@ -83,6 +83,11 @@ default List<Slot> getOutput() {
         throw new RuntimeException("Command do not implement getOutput");
     }
 
+    @Override
+    default List<Slot> getNonUserVisibleOutput() {
+        throw new RuntimeException("Command do not implement getNonUserVisibleOutput");

Review Comment:
    I think both choices are ok. Just keep consistent with `Command.getOutput`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org