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/22 16:11:14 UTC

[GitHub] [doris] morrySnow commented on a diff in pull request #15275: [Feature](Nereids) Support hll and count for materialized index.

morrySnow commented on code in PR #15275:
URL: https://github.com/apache/doris/pull/15275#discussion_r1055615863


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/Ndv.java:
##########
@@ -0,0 +1,117 @@
+// 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.trees.expressions.functions.agg;
+
+import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.functions.AlwaysNotNullable;
+import org.apache.doris.nereids.trees.expressions.functions.ExplicitlyCastableSignature;
+import org.apache.doris.nereids.trees.expressions.shape.UnaryExpression;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.BitmapType;
+import org.apache.doris.nereids.types.BooleanType;
+import org.apache.doris.nereids.types.DateTimeType;
+import org.apache.doris.nereids.types.DateTimeV2Type;
+import org.apache.doris.nereids.types.DateType;
+import org.apache.doris.nereids.types.DateV2Type;
+import org.apache.doris.nereids.types.DecimalV2Type;
+import org.apache.doris.nereids.types.DecimalV3Type;
+import org.apache.doris.nereids.types.DoubleType;
+import org.apache.doris.nereids.types.FloatType;
+import org.apache.doris.nereids.types.HllType;
+import org.apache.doris.nereids.types.IntegerType;
+import org.apache.doris.nereids.types.JsonType;
+import org.apache.doris.nereids.types.LargeIntType;
+import org.apache.doris.nereids.types.QuantileStateType;
+import org.apache.doris.nereids.types.SmallIntType;
+import org.apache.doris.nereids.types.StringType;
+import org.apache.doris.nereids.types.TimeType;
+import org.apache.doris.nereids.types.TimeV2Type;
+import org.apache.doris.nereids.types.TinyIntType;
+import org.apache.doris.nereids.types.VarcharType;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+import java.util.List;
+
+/**
+ * AggregateFunction 'ndv'. This class is generated by GenerateFunction.
+ */
+public class Ndv extends AggregateFunction
+        implements UnaryExpression, ExplicitlyCastableSignature, AlwaysNotNullable {
+
+    public static final List<FunctionSignature> SIGNATURES = ImmutableList.of(
+            FunctionSignature.ret(BigIntType.INSTANCE).args(TinyIntType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(SmallIntType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(IntegerType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(BigIntType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(LargeIntType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(FloatType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DoubleType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DecimalV2Type.SYSTEM_DEFAULT),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DecimalV3Type.DEFAULT_DECIMAL32),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DecimalV3Type.DEFAULT_DECIMAL64),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DecimalV3Type.DEFAULT_DECIMAL128),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(BooleanType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(VarcharType.SYSTEM_DEFAULT),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(StringType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DateType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DateTimeType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DateV2Type.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(DateTimeV2Type.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(TimeType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(TimeV2Type.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(JsonType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(HllType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(BitmapType.INSTANCE),
+            FunctionSignature.ret(BigIntType.INSTANCE).args(QuantileStateType.INSTANCE)

Review Comment:
   legacy planner also support NULL_TYPE and CharType



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/mv/SelectMaterializedIndexWithAggregate.java:
##########
@@ -328,6 +330,13 @@ private SelectResult select(
                         .filter(index -> !candidatesWithoutRewriting.contains(index))
                         .map(index -> rewriteAgg(index, scan, requiredScanOutput, predicates, aggregateFunctions,
                                 groupingExprs))
+                        .filter(aggRewriteResult -> checkPreAggStatus(scan, aggRewriteResult.index.getId(),
+                                predicates,
+                                // check pre-agg status of aggregate function that couldn't rewrite.
+                                // ImmutableList.copyOf(Sets.difference(ImmutableSet.copyOf(aggregateFunctions),
+                                //         aggRewriteResult.exprRewriteMap.aggFuncMap.keySet())),

Review Comment:
    useless code



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/mv/SelectMaterializedIndexWithAggregate.java:
##########
@@ -711,34 +746,62 @@ private static Expression rewrite(Expression expr, RewriteContext context) {
 
         /**
          * count(distinct col) -> bitmap_union_count(mv_bitmap_union_col)
+         * count(col) -> sum(mv_count_col)
          */
         @Override
         public Expression visitCount(Count count, RewriteContext context) {
             if (count.isDistinct() && count.arity() == 1) {

Review Comment:
   should the AggFuncRewriter process children first in each visit function? such as
   ```
   public Expression visitCount(Count count, RewriteContext context) {
       List<Expression> children = count.children().stream().map(e -> this.rewrite(e, context)).collect(Collectors.toList());
       ...
   }
   ```



-- 
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