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/07/31 12:07:57 UTC

[GitHub] [doris] yinzhijian opened a new pull request, #11374: [enhancement](Nereids)support count, min and avg function

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

   # Proposed changes
   
   Issue Number: close #xxx
   
   ## Problem Summary:
   1. add count function
   2. add min function
   3. add avg function
   ## Checklist(Required)
   
   1. Does it affect the original behavior: 
       - [ ] Yes
       - [x] No
       - [ ] I don't know
   4. Has unit tests been added:
       - [x] Yes
       - [ ] No
       - [ ] No Need
   5. Has document been added or modified:
       - [ ] Yes
       - [ ] No
       - [x] No Need
   6. Does it need to update dependencies:
       - [ ] Yes
       - [x] No
   7. Are there any changes that cannot be rolled back:
       - [ ] Yes
       - [x] 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] github-actions[bot] commented on pull request #11374: [enhancement](Nereids)support count, min and avg function

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on PR #11374:
URL: https://github.com/apache/doris/pull/11374#issuecomment-1200629643

   PR approved by anyone and no changes requested.


-- 
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] morrySnow commented on a diff in pull request #11374: [enhancement](Nereids)support count, min and avg function

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindSlotReference.java:
##########
@@ -282,6 +282,10 @@ public BoundStar(List<Slot> children) {
             );
         }
 
+        public String toSql() {
+            return children.stream().map(Expression::toSql).collect(Collectors.joining(","));

Review Comment:
   nit:
   ```suggestion
               return children.stream().map(Expression::toSql).collect(Collectors.joining(", "));
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindFunction.java:
##########
@@ -90,6 +93,24 @@ public Expression visitUnboundFunction(UnboundFunction unboundFunction, Void con
                     return unboundFunction;
                 }
                 return new Sum(unboundFunction.getArguments().get(0));
+            } else if (name.equalsIgnoreCase("count")) {
+                List<Expression> arguments = unboundFunction.getArguments();
+                if (arguments.size() != 1) {
+                    return unboundFunction;
+                }
+                return new Count(unboundFunction.getArguments().get(0));

Review Comment:
   could we handle count(*) and count(1) now?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Avg.java:
##########
@@ -0,0 +1,56 @@
+// 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;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.UnaryExpression;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.DoubleType;
+
+import com.google.common.base.Preconditions;
+
+import java.util.List;
+
+/** avg agg function. */
+public class Avg extends AggregateFunction implements UnaryExpression {
+
+    public Avg(Expression child) {
+        super("avg", child);
+    }
+
+    @Override
+    public DataType getDataType() {
+        return DoubleType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() {
+        return child().nullable();
+    }
+
+    @Override
+    public Expression withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() == 1);
+        return new Avg(children.get(0));
+    }
+
+    @Override
+    public DataType getIntermediateType() {
+        return getDataType();

Review Comment:
   avg's IntermediateType is not consistent with Function data type



-- 
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] morrySnow commented on a diff in pull request #11374: [enhancement](Nereids)support count, min and avg function

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/Count.java:
##########
@@ -0,0 +1,96 @@
+// 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;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.types.BigIntType;
+import org.apache.doris.nereids.types.DataType;
+
+import com.google.common.base.Preconditions;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+/** count agg function. */
+public class Count extends AggregateFunction {
+
+    private final boolean isStar;
+
+    public Count() {
+        super("count");
+        this.isStar = true;

Review Comment:
   we need to handle count(1) and count(*) in PruneAggChildColumns. 



-- 
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 #11374: [enhancement](Nereids)support count, min and avg function

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


-- 
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 pull request #11374: [enhancement](Nereids)support count, min and avg function

Posted by GitBox <gi...@apache.org>.
924060929 commented on PR #11374:
URL: https://github.com/apache/doris/pull/11374#issuecomment-1200678098

   good job, you can add some regression test suite like this?
   
   ```groovy
   suite('test_aggregate_function') {
       // use regression_test_ssb_sf1 database, you can compute ssb database by suite directory like 'regression-test/suites/ssb_sf1/nereids/q1.1.groovy'
       sql "use ${realDb}"
   
       sql 'set enable_nereids_planner=true'
       // nereids need vectorized
       sql 'set enable_vectorized_engine=true'
   
       sql 'set exec_mem_limit=2147483648*2'
   
       qt 'select count(*), count(l.*), count(1), count(lo_orderkey), count(l.lo_orderkey), min(lo_revenue), min(l.lo_revenue), avg(lo_revenue), avg(l.lo_revenue) from lineorder as l'
   }
   ```


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