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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java:
##########
@@ -0,0 +1,74 @@
+// 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.analysis;
+
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.trees.expressions.Divide;
+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.AggregateFunction;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Avg;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.collect.ImmutableMap;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * AvgDistinctToSumDivCount.
+ *
+ * change avg( distinct a ) into sum( distinct a ) / count( distinct a ) if 
there are more than 1 distinct arguments
+ */
+public class AvgDistinctToSumDivCount extends OneAnalysisRuleFactory {
+    @Override
+    public Rule build() {
+        return RuleType.AVG_DISTINCT_TO_SUM_DIV_COUNT.build(
+                logicalAggregate().then(agg -> {
+                    if (agg.getDistinctArguments().size() > 1) {

Review Comment:
   nit: could use when:
   ```suggestion
                   logicalAggregate().when(agg -> 
agg.getDistinctArguments().size() > 1).then(agg -> {
                       ...
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AggregateStrategies.java:
##########
@@ -781,7 +781,7 @@ private List<PhysicalHashAggregate<? extends Plan>> 
twoPhaseAggregateWithDistinc
                 false, Optional.empty(), logicalAgg.getLogicalProperties(),
                 requireGather, logicalAgg.child());
 
-        AggregateParam inputToResultParam = new 
AggregateParam(AggPhase.GLOBAL, AggMode.INPUT_TO_RESULT);
+        AggregateParam inputToResultParam = new 
AggregateParam(AggPhase.GLOBAL, AggMode.BUFFER_TO_RESULT);

Review Comment:
   ```suggestion
           AggregateParam bufferToResultParam = new 
AggregateParam(AggPhase.GLOBAL, AggMode.BUFFER_TO_RESULT);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AvgDistinctToSumDivCount.java:
##########
@@ -0,0 +1,74 @@
+// 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.analysis;
+
+import org.apache.doris.nereids.rules.Rule;
+import org.apache.doris.nereids.rules.RuleType;
+import org.apache.doris.nereids.trees.expressions.Divide;
+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.AggregateFunction;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Avg;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Count;
+import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
+import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.collect.ImmutableMap;
+
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+ * AvgDistinctToSumDivCount.
+ *
+ * change avg( distinct a ) into sum( distinct a ) / count( distinct a ) if 
there are more than 1 distinct arguments
+ */
+public class AvgDistinctToSumDivCount extends OneAnalysisRuleFactory {
+    @Override
+    public Rule build() {
+        return RuleType.AVG_DISTINCT_TO_SUM_DIV_COUNT.build(
+                logicalAggregate().then(agg -> {
+                    if (agg.getDistinctArguments().size() > 1) {

Review Comment:
   nit: could use when:
   ```suggestion
                   logicalAggregate().when(agg -> 
agg.getDistinctArguments().size() > 1).then(agg -> {
                       ...
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AggregateStrategies.java:
##########
@@ -781,7 +781,7 @@ private List<PhysicalHashAggregate<? extends Plan>> 
twoPhaseAggregateWithDistinc
                 false, Optional.empty(), logicalAgg.getLogicalProperties(),
                 requireGather, logicalAgg.child());
 
-        AggregateParam inputToResultParam = new 
AggregateParam(AggPhase.GLOBAL, AggMode.INPUT_TO_RESULT);
+        AggregateParam inputToResultParam = new 
AggregateParam(AggPhase.GLOBAL, AggMode.BUFFER_TO_RESULT);

Review Comment:
   ```suggestion
           AggregateParam bufferToResultParam = new 
AggregateParam(AggPhase.GLOBAL, AggMode.BUFFER_TO_RESULT);
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/logical/InApplyToJoin.java:
##########
@@ -51,15 +56,19 @@ public Rule build() {
                 predicate = new EqualTo(((InSubquery) 
apply.getSubqueryExpr()).getCompareExpr(),
                         apply.right().getOutput().get(0));
             }
-
+            List<Expression> conjuncts = 
ExpressionUtils.extractConjunction(predicate);
+            if (conjuncts.stream().anyMatch(expression -> 
expression.children().stream()
+                    .anyMatch(expr -> expr.getDataType() == 
BitmapType.INSTANCE))) {
+                throw new NereidsException(new AnalysisException("nereids 
don't support bitmap filter"));

Review Comment:
   add a TODO on it, we will fix it later.
   ```suggestion
                   throw new AnalysisException("nereids don't support bitmap 
filter");
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/agg/MultiDistinctCount.java:
##########
@@ -18,28 +18,39 @@
 package org.apache.doris.nereids.trees.expressions.functions.agg;
 
 import org.apache.doris.catalog.FunctionSignature;
+import org.apache.doris.nereids.trees.expressions.Cast;
 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.visitor.ExpressionVisitor;
 import org.apache.doris.nereids.types.BigIntType;
 import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.coercion.DateLikeType;
 import org.apache.doris.nereids.util.ExpressionUtils;
 
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 import java.util.List;
+import java.util.stream.Collectors;
 
 /** MultiDistinctCount */
 public class MultiDistinctCount extends AggregateFunction
         implements AlwaysNotNullable, ExplicitlyCastableSignature {
     public MultiDistinctCount(Expression arg0, Expression... varArgs) {
-        super("multi_distinct_count", true, 
ExpressionUtils.mergeArguments(arg0, varArgs));
+        super("multi_distinct_count", true, 
ExpressionUtils.mergeArguments(arg0, varArgs).stream()
+                .map(arg -> arg.getDataType() instanceof DateLikeType ? new 
Cast(arg, BigIntType.INSTANCE)
+                        : arg)
+                .collect(
+                        Collectors.toList()));

Review Comment:
   i think we should change getSignatures, return BigIntType on DateLikeType 
args.
   ```suggestion
           super("multi_distinct_count", true, 
ExpressionUtils.mergeArguments(arg0, varArgs).stream()
                   .map(arg -> arg.getDataType() instanceof DateLikeType
                           ? new Cast(arg, BigIntType.INSTANCE) : arg)
                   .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-unsubscr...@doris.apache.org

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


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

Reply via email to