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/06/17 11:45:02 UTC

[GitHub] [doris] zhengshiJ opened a new pull request, #10227: [feature](nereids) Add ssb related expressions

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

   # Proposed changes
   
   Add related expressions and AggPlan and SortPlan.
   
   ## Problem Summary:
   
   Describe the overview of changes.
   
   ## Checklist(Required)
   
   1. Does it affect the original behavior: (No)
   2. Has unit tests been added: (Yes)
   3. Has document been added or modified: (No)
   4. Does it need to update dependencies: (No)
   5. Are there any changes that cannot be rolled back: (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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Literal.java:
##########
@@ -109,7 +109,7 @@ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
 
     @Override
     public String sql() {
-        return null;
+        return value.toString();

Review Comment:
   Added todo information, which is subsequently rewritten in subexpressions



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;
+    private final List<? extends NamedExpression> aggExpressions;
+
+    /**
+     * Desc: Constructor for LogicalAggregation.
+     */
+    public LogicalAggregation(List<? extends NamedExpression> groupByExpressions,
+            List<? extends NamedExpression> aggExpressions) {
+        super(OperatorType.LOGICAL_AGGREGATION);
+        this.groupByExpressions = Objects.requireNonNull(groupByExpressions, "groupByExpressions can not be null");

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -278,6 +318,64 @@ last, plan(join.relationPrimary())
         return last;
     }
 
+    private LogicalPlan withAggClause(List<NamedExpression> aggExpressions,
+            GroupByItemContext ctx, LogicalPlan aggClause) {
+        List<Expression> tmpExpressions = new ArrayList<>();
+        for (ExpressionContext expressionCtx : ctx.expression()) {
+            tmpExpressions.add(typedVisit(expressionCtx));
+        }
+        List<NamedExpression> groupByExpressions = tmpExpressions.stream().map(expression -> {
+            if (expression instanceof NamedExpression) {
+                return (NamedExpression) expression;
+            } else {
+                return new UnboundAlias(expression);
+            }
+        }).collect(Collectors.toList());
+        return new LogicalUnaryPlan(new LogicalAggregation(groupByExpressions, aggExpressions), aggClause);
+    }
+
+    /**
+     * Generate sortItems.
+     *
+     * @param ctx SortItemContext
+     * @return SortItems
+     */
+    public SortItems genSortItems(SortItemContext ctx) {
+        OrderDirection orderDirection;
+        if (ctx.DESC() != null) {
+            orderDirection = OrderDirection.DESC;
+        } else {
+            orderDirection = OrderDirection.ASC;
+        }
+        Expression expression = typedVisit(ctx.expression());
+        NamedExpression namedExpression;
+        if (expression instanceof NamedExpression) {

Review Comment:
   done



-- 
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] EmmyMiao87 commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {

Review Comment:
   In the comments, please explain the meaning of each attribute directly, and give an example in combination with the real sql statement.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalSort.java:
##########
@@ -0,0 +1,101 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+    Logical Sort plan operator.
+ */

Review Comment:
   Please update commit as above ~



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -278,6 +318,64 @@ last, plan(join.relationPrimary())
         return last;
     }
 
+    private LogicalPlan withAggClause(List<NamedExpression> aggExpressions,
+            GroupByItemContext ctx, LogicalPlan aggClause) {
+        List<Expression> tmpExpressions = new ArrayList<>();
+        for (ExpressionContext expressionCtx : ctx.expression()) {
+            tmpExpressions.add(typedVisit(expressionCtx));
+        }
+        List<NamedExpression> groupByExpressions = tmpExpressions.stream().map(expression -> {
+            if (expression instanceof NamedExpression) {
+                return (NamedExpression) expression;
+            } else {
+                return new UnboundAlias(expression);
+            }
+        }).collect(Collectors.toList());
+        return new LogicalUnaryPlan(new LogicalAggregation(groupByExpressions, aggExpressions), aggClause);
+    }
+
+    /**
+     * Generate sortItems.
+     *
+     * @param ctx SortItemContext
+     * @return SortItems
+     */
+    public SortItems genSortItems(SortItemContext ctx) {
+        OrderDirection orderDirection;
+        if (ctx.DESC() != null) {
+            orderDirection = OrderDirection.DESC;
+        } else {
+            orderDirection = OrderDirection.ASC;
+        }
+        Expression expression = typedVisit(ctx.expression());
+        NamedExpression namedExpression;
+        if (expression instanceof NamedExpression) {

Review Comment:
   Why convert all expr to namedexpr? Is there any special purpose?
   I give an example
   ```
   select a.k1+a.k2 from a order by 1
   ```
   then the original sort item should be intliteral(1)
   



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/OperatorType.java:
##########
@@ -35,6 +35,8 @@ public enum OperatorType {
     LOGICAL_FILTER,
     LOGICAL_JOIN,
     PLACE_HOLDER,

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;

Review Comment:
   done



-- 
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] EmmyMiao87 commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CompoundPredicate.java:
##########
@@ -0,0 +1,50 @@
+// 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;
+
+import org.apache.doris.nereids.rules.expression.rewrite.ExpressionVisitor;
+import org.apache.doris.nereids.trees.NodeType;
+
+/**
+ * Compound predicate expression.
+ * Such as &&,||,AND,OR.
+ */
+public class CompoundPredicate<LEFT_CHILD_TYPE extends Expression, RIGHT_CHILD_TYPE extends Expression>

Review Comment:
   According to what we discussed before, in terms of expressions, try not to use the combination + inheritance method but directly use the inheritance method.
   So I suggest that there should be `and`, `or` two separate expr classes and unified inheritance from `compoundpredicate`.



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -178,6 +221,12 @@ booleanValue
     : TRUE | FALSE
     ;
 
+aggFunction
+    : AVG '(' DISTINCT? expression ')'

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,75 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> aggregation;

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalSort.java:
##########
@@ -0,0 +1,103 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+    Logical Sort plan operator.
+ */
+public class LogicalSort extends LogicalUnaryOperator {
+
+    private List<SortItems> sortItems;
+
+    /**
+     * Constructor for SortItems.
+     */
+    public LogicalSort(List<SortItems> sortItems) {
+        super(OperatorType.LOGICAL_SORT);
+        this.sortItems = Objects.requireNonNull(sortItems, "sorItems can not be null");
+    }
+
+    @Override
+    public String toString() {
+        return "Sort (" + StringUtils.join(sortItems, ", ") + ")";
+    }
+
+    @Override
+    public List<Slot> computeOutput(Plan input) {
+        return sortItems.stream()
+                .map(namedExpr -> {
+                    try {
+                        return namedExpr.getSort().toSlot();
+                    } catch (UnboundException e) {
+                        throw new IllegalStateException(e);
+                    }
+                })
+                .collect(ImmutableList.toImmutableList());

Review Comment:
   done



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -132,11 +153,18 @@ private LogicalPlan plan(ParserRuleContext tree) {
     public LogicalPlan visitQuery(QueryContext ctx) {
         Supplier<LogicalPlan> f = () -> {
             // TODO: need to add withQueryResultClauses and withCTE
-            return plan(ctx.queryTerm());
+            LogicalPlan query = plan(ctx.queryTerm());
+            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            return queryOrganization == null ? query : queryOrganization;
         };
         return ParserUtils.withOrigin(ctx, f);
     }
 
+    private LogicalPlan withQueryOrganization(QueryOrganizationContext ctx, LogicalPlan children) {
+        List<SortItems> sortItems = visitQueryOrganization(ctx);
+        return sortItems == null ? null : new LogicalUnaryPlan(new LogicalSort(sortItems), children);

Review Comment:
   done



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalSort.java:
##########
@@ -0,0 +1,101 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+    Logical Sort plan operator.
+ */

Review Comment:
   done



-- 
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 #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -278,6 +317,70 @@ last, plan(join.relationPrimary())
         return last;
     }
 
+    private LogicalPlan withAggClause(List<Expression> expressions,
+            GroupByItemContext ctx, LogicalPlan aggClause) {
+        List<Expression> tmpExpressions = new ArrayList<>();
+        for (ExpressionContext expressionCtx : ctx.expression()) {
+            tmpExpressions.add(typedVisit(expressionCtx));
+        }
+        List<NamedExpression> groupByExpressions = tmpExpressions.stream().map(expression -> {
+            if (expression instanceof NamedExpression) {
+                return (NamedExpression) expression;
+            } else {
+                return new UnboundAlias(expression);
+            }
+        }).collect(Collectors.toList());
+        List<Expression> aggExpressions = new ArrayList<>();
+        for (Expression expression : expressions) {
+            if (expression instanceof FunctionCall) {
+                aggExpressions.add(expression);
+            }
+        }
+        return new LogicalUnaryPlan(new LogicalAggregation(groupByExpressions, aggExpressions), aggClause);
+    }
+
+    /**
+     * Generate sortItems.
+     *
+     * @param ctx SortItemContext
+     * @return SortItems
+     */
+    public SortItems genSortItems(SortItemContext ctx) {
+        boolean orderDirection = true;
+        if (ctx.DESC() != null) {
+            orderDirection = false;

Review Comment:
   maybe a enum is better than a boolean



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -278,6 +317,70 @@ last, plan(join.relationPrimary())
         return last;
     }
 
+    private LogicalPlan withAggClause(List<Expression> expressions,
+            GroupByItemContext ctx, LogicalPlan aggClause) {
+        List<Expression> tmpExpressions = new ArrayList<>();
+        for (ExpressionContext expressionCtx : ctx.expression()) {
+            tmpExpressions.add(typedVisit(expressionCtx));
+        }
+        List<NamedExpression> groupByExpressions = tmpExpressions.stream().map(expression -> {
+            if (expression instanceof NamedExpression) {
+                return (NamedExpression) expression;
+            } else {
+                return new UnboundAlias(expression);
+            }
+        }).collect(Collectors.toList());
+        List<Expression> aggExpressions = new ArrayList<>();
+        for (Expression expression : expressions) {
+            if (expression instanceof FunctionCall) {

Review Comment:
   should put all expression to aggExpressions, not only function call



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,87 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;
+    private final List<Expression> aggExpressions;
+
+    /**
+     * Desc: Constructor for LogicalAggregation.
+     */
+    public LogicalAggregation(List<? extends NamedExpression> groupByExpressions,
+            List<Expression> aggExpressions) {
+        super(OperatorType.LOGICAL_AGGREGATION);
+        this.groupByExpressions = Objects.requireNonNull(groupByExpressions, "groupByExpressions can not be null");
+        this.aggExpressions = aggExpressions;
+    }
+
+    /**
+     * Get GroupByAggregation list.
+     *
+     * @return all group by of this node.
+     */
+    public List<? extends NamedExpression> getGroupByExpressions() {
+        return groupByExpressions;
+    }
+
+    /**
+     * Get AggExpressions list.
+     *
+     * @return all agg expressions.
+     */
+    public List<Expression> getAggExpressions() {
+        return aggExpressions;
+    }
+
+    @Override
+    public String toString() {
+        return "Aggregation (" + StringUtils.join(groupByExpressions, ", ")
+                + StringUtils.join(aggExpressions, ", ") + ")";
+    }
+
+    @Override
+    public List<Slot> computeOutput(Plan input) {
+        return groupByExpressions.stream()

Review Comment:
   use agg expressions instead of group by



-- 
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] EmmyMiao87 commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;
+    private final List<? extends NamedExpression> aggExpressions;
+
+    /**
+     * Desc: Constructor for LogicalAggregation.
+     */
+    public LogicalAggregation(List<? extends NamedExpression> groupByExpressions,
+            List<? extends NamedExpression> aggExpressions) {
+        super(OperatorType.LOGICAL_AGGREGATION);
+        this.groupByExpressions = Objects.requireNonNull(groupByExpressions, "groupByExpressions can not be null");

Review Comment:
   Both group by and agg can be null respectively.
   for example
   ```
   select sum(a) from test
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/OperatorType.java:
##########
@@ -35,6 +35,8 @@ public enum OperatorType {
     LOGICAL_FILTER,
     LOGICAL_JOIN,
     PLACE_HOLDER,

Review Comment:
   Put PLACE_HOLDER in the end



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;

Review Comment:
   Both group by columns and agg columns may be functioncalls. So I think the list generic here should be expression more appropriate.
   ```
   select k1+k1 from test_join group by k1+k1;
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;
+    private final List<? extends NamedExpression> aggExpressions;
+
+    /**
+     * Desc: Constructor for LogicalAggregation.
+     */
+    public LogicalAggregation(List<? extends NamedExpression> groupByExpressions,
+            List<? extends NamedExpression> aggExpressions) {
+        super(OperatorType.LOGICAL_AGGREGATION);
+        this.groupByExpressions = Objects.requireNonNull(groupByExpressions, "groupByExpressions can not be null");
+        this.aggExpressions = aggExpressions;
+    }
+
+    /**
+     * Get GroupByAggregation list.
+     *
+     * @return all group by of this node.
+     */
+    public List<? extends NamedExpression> getGroupByExpressions() {
+        return groupByExpressions;
+    }
+
+    /**
+     * Get AggExpressions list.
+     *
+     * @return all agg expressions.
+     */
+    public List<? extends NamedExpression> getAggExpressions() {
+        return aggExpressions;
+    }
+
+    @Override
+    public String toString() {
+        return "Aggregation (" + StringUtils.join(groupByExpressions, ", ")
+                + StringUtils.join(aggExpressions, ", ") + ")";
+    }
+
+    @Override
+    public List<Slot> computeOutput(Plan input) {
+        return aggExpressions.stream()

Review Comment:
   Output should be the agg expr + group by 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] morrySnow commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -162,7 +192,7 @@ public List<Expression> visitNamedExpressionSeq(NamedExpressionSeqContext ctx) {
         List<Expression> expressions = Lists.newArrayList();
         if (ctx != null) {
             for (NamedExpressionContext namedExpressionContext : ctx.namedExpression()) {
-                NamedExpression namedExpression = typedVisit(namedExpressionContext);
+                Expression namedExpression = typedVisit(namedExpressionContext);
                 expressions.add(namedExpression);

Review Comment:
   ```suggestion
                   Expression expression = typedVisit(namedExpressionContext);
                   expressions.add(expression);
   ```



-- 
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] EmmyMiao87 commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;
+    private final List<? extends NamedExpression> aggExpressions;
+
+    /**
+     * Desc: Constructor for LogicalAggregation.
+     */
+    public LogicalAggregation(List<? extends NamedExpression> groupByExpressions,
+            List<? extends NamedExpression> aggExpressions) {
+        super(OperatorType.LOGICAL_AGGREGATION);
+        this.groupByExpressions = Objects.requireNonNull(groupByExpressions, "groupByExpressions can not be null");
+        this.aggExpressions = aggExpressions;
+    }
+
+    /**
+     * Get GroupByAggregation list.
+     *
+     * @return all group by of this node.
+     */
+    public List<? extends NamedExpression> getGroupByExpressions() {
+        return groupByExpressions;
+    }
+
+    /**
+     * Get AggExpressions list.
+     *
+     * @return all agg expressions.
+     */
+    public List<? extends NamedExpression> getAggExpressions() {
+        return aggExpressions;
+    }
+
+    @Override
+    public String toString() {
+        return "Aggregation (" + StringUtils.join(groupByExpressions, ", ")
+                + StringUtils.join(aggExpressions, ", ") + ")";
+    }
+
+    @Override
+    public List<Slot> computeOutput(Plan input) {
+        return aggExpressions.stream()

Review Comment:
   Output should be the agg expr + group by 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] morningman merged pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/CompoundPredicate.java:
##########
@@ -0,0 +1,50 @@
+// 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;
+
+import org.apache.doris.nereids.rules.expression.rewrite.ExpressionVisitor;
+import org.apache.doris.nereids.trees.NodeType;
+
+/**
+ * Compound predicate expression.
+ * Such as &&,||,AND,OR.
+ */
+public class CompoundPredicate<LEFT_CHILD_TYPE extends Expression, RIGHT_CHILD_TYPE extends Expression>

Review Comment:
   done



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -162,7 +192,7 @@ public List<Expression> visitNamedExpressionSeq(NamedExpressionSeqContext ctx) {
         List<Expression> expressions = Lists.newArrayList();
         if (ctx != null) {
             for (NamedExpressionContext namedExpressionContext : ctx.namedExpression()) {
-                NamedExpression namedExpression = typedVisit(namedExpressionContext);
+                Expression namedExpression = typedVisit(namedExpressionContext);
                 expressions.add(namedExpression);

Review Comment:
   done



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -218,7 +251,14 @@ private LogicalPlan visitCommonSelectQueryClausePlan(
             withProject = withFilter;
         }
 
-        return withProject;
+        LogicalPlan withAgg;
+        if (aggClause != null) {

Review Comment:
   done



-- 
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 #10227: [feature](nereids) Add ssb related expressions and PlanNode

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

   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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BetweenPredicate.java:
##########
@@ -0,0 +1,85 @@
+// 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;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.rules.expression.rewrite.ExpressionVisitor;
+import org.apache.doris.nereids.trees.NodeType;
+import org.apache.doris.nereids.types.BooleanType;
+import org.apache.doris.nereids.types.DataType;
+
+/**
+ * Between predicate expression.
+ */
+public class BetweenPredicate extends Expression {
+
+    private boolean isNotBetween;

Review Comment:
   done



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,87 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;
+    private final List<Expression> aggExpressions;
+
+    /**
+     * Desc: Constructor for LogicalAggregation.
+     */
+    public LogicalAggregation(List<? extends NamedExpression> groupByExpressions,
+            List<Expression> aggExpressions) {
+        super(OperatorType.LOGICAL_AGGREGATION);
+        this.groupByExpressions = Objects.requireNonNull(groupByExpressions, "groupByExpressions can not be null");
+        this.aggExpressions = aggExpressions;
+    }
+
+    /**
+     * Get GroupByAggregation list.
+     *
+     * @return all group by of this node.
+     */
+    public List<? extends NamedExpression> getGroupByExpressions() {
+        return groupByExpressions;
+    }
+
+    /**
+     * Get AggExpressions list.
+     *
+     * @return all agg expressions.
+     */
+    public List<Expression> getAggExpressions() {
+        return aggExpressions;
+    }
+
+    @Override
+    public String toString() {
+        return "Aggregation (" + StringUtils.join(groupByExpressions, ", ")
+                + StringUtils.join(aggExpressions, ", ") + ")";
+    }
+
+    @Override
+    public List<Slot> computeOutput(Plan input) {
+        return groupByExpressions.stream()

Review Comment:
   done



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -278,6 +317,70 @@ last, plan(join.relationPrimary())
         return last;
     }
 
+    private LogicalPlan withAggClause(List<Expression> expressions,
+            GroupByItemContext ctx, LogicalPlan aggClause) {
+        List<Expression> tmpExpressions = new ArrayList<>();
+        for (ExpressionContext expressionCtx : ctx.expression()) {
+            tmpExpressions.add(typedVisit(expressionCtx));
+        }
+        List<NamedExpression> groupByExpressions = tmpExpressions.stream().map(expression -> {
+            if (expression instanceof NamedExpression) {
+                return (NamedExpression) expression;
+            } else {
+                return new UnboundAlias(expression);
+            }
+        }).collect(Collectors.toList());
+        List<Expression> aggExpressions = new ArrayList<>();
+        for (Expression expression : expressions) {
+            if (expression instanceof FunctionCall) {
+                aggExpressions.add(expression);
+            }
+        }
+        return new LogicalUnaryPlan(new LogicalAggregation(groupByExpressions, aggExpressions), aggClause);
+    }
+
+    /**
+     * Generate sortItems.
+     *
+     * @param ctx SortItemContext
+     * @return SortItems
+     */
+    public SortItems genSortItems(SortItemContext ctx) {
+        boolean orderDirection = true;
+        if (ctx.DESC() != null) {
+            orderDirection = false;

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -278,6 +317,70 @@ last, plan(join.relationPrimary())
         return last;
     }
 
+    private LogicalPlan withAggClause(List<Expression> expressions,
+            GroupByItemContext ctx, LogicalPlan aggClause) {
+        List<Expression> tmpExpressions = new ArrayList<>();
+        for (ExpressionContext expressionCtx : ctx.expression()) {
+            tmpExpressions.add(typedVisit(expressionCtx));
+        }
+        List<NamedExpression> groupByExpressions = tmpExpressions.stream().map(expression -> {
+            if (expression instanceof NamedExpression) {
+                return (NamedExpression) expression;
+            } else {
+                return new UnboundAlias(expression);
+            }
+        }).collect(Collectors.toList());
+        List<Expression> aggExpressions = new ArrayList<>();
+        for (Expression expression : expressions) {
+            if (expression instanceof FunctionCall) {

Review Comment:
   done
   



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/analysis/FunctionParams.java:
##########
@@ -0,0 +1,83 @@
+// 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.analysis;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Function's Params.
+ */
+public class FunctionParams {
+    private boolean isStar;

Review Comment:
   Just refer to the structure of the old optimizer



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -132,11 +153,18 @@ private LogicalPlan plan(ParserRuleContext tree) {
     public LogicalPlan visitQuery(QueryContext ctx) {
         Supplier<LogicalPlan> f = () -> {
             // TODO: need to add withQueryResultClauses and withCTE
-            return plan(ctx.queryTerm());
+            LogicalPlan query = plan(ctx.queryTerm());
+            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            return queryOrganization == null ? query : queryOrganization;

Review Comment:
   done



-- 
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 #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> groupByExpressions;
+    private final List<? extends NamedExpression> aggExpressions;
+
+    /**
+     * Desc: Constructor for LogicalAggregation.
+     */
+    public LogicalAggregation(List<? extends NamedExpression> groupByExpressions,
+            List<? extends NamedExpression> aggExpressions) {
+        super(OperatorType.LOGICAL_AGGREGATION);
+        this.groupByExpressions = Objects.requireNonNull(groupByExpressions, "groupByExpressions can not be null");

Review Comment:
   currently we use empty list to do that



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/OperatorType.java:
##########
@@ -35,6 +35,8 @@ public enum OperatorType {
     LOGICAL_FILTER,
     LOGICAL_JOIN,
     PLACE_HOLDER,

Review Comment:
   > Put PLACE_HOLDER in the end
   
   place holder has been removed by #10241 



-- 
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 #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -218,7 +251,14 @@ private LogicalPlan visitCommonSelectQueryClausePlan(
             withProject = withFilter;
         }
 
-        return withProject;
+        LogicalPlan withAgg;
+        if (aggClause != null) {

Review Comment:
   we should do with project only when aggClause is null



-- 
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] zhengshiJ commented on a diff in pull request #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,86 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {

Review Comment:
   done



-- 
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 #10227: [feature](nereids) Add ssb related expressions and PlanNode

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


##########
fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4:
##########
@@ -178,6 +221,12 @@ booleanValue
     : TRUE | FALSE
     ;
 
+aggFunction
+    : AVG '(' DISTINCT? expression ')'

Review Comment:
   Is this a temporary solution? it is better not add any function name here.
   If this is a temporary solution, please add a todo comment.



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Literal.java:
##########
@@ -109,7 +109,7 @@ public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
 
     @Override
     public String sql() {
-        return null;
+        return value.toString();

Review Comment:
   Should we break them down into separate expressions @EmmyMiao87 ?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/analysis/FunctionParams.java:
##########
@@ -0,0 +1,83 @@
+// 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.analysis;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+
+import com.google.common.collect.Lists;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Function's Params.
+ */
+public class FunctionParams {
+    private boolean isStar;

Review Comment:
   just curious, why FunctionParams is a top level class, but SortItem is an inner class?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalSort.java:
##########
@@ -0,0 +1,103 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+    Logical Sort plan operator.
+ */
+public class LogicalSort extends LogicalUnaryOperator {
+
+    private List<SortItems> sortItems;
+
+    /**
+     * Constructor for SortItems.
+     */
+    public LogicalSort(List<SortItems> sortItems) {
+        super(OperatorType.LOGICAL_SORT);
+        this.sortItems = Objects.requireNonNull(sortItems, "sorItems can not be null");
+    }
+
+    @Override
+    public String toString() {
+        return "Sort (" + StringUtils.join(sortItems, ", ") + ")";
+    }
+
+    @Override
+    public List<Slot> computeOutput(Plan input) {
+        return sortItems.stream()
+                .map(namedExpr -> {
+                    try {
+                        return namedExpr.getSort().toSlot();
+                    } catch (UnboundException e) {
+                        throw new IllegalStateException(e);
+                    }
+                })
+                .collect(ImmutableList.toImmutableList());

Review Comment:
   sort node's output should just return child's output, but not use sort item



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BetweenPredicate.java:
##########
@@ -0,0 +1,85 @@
+// 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;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.rules.expression.rewrite.ExpressionVisitor;
+import org.apache.doris.nereids.trees.NodeType;
+import org.apache.doris.nereids.types.BooleanType;
+import org.apache.doris.nereids.types.DataType;
+
+/**
+ * Between predicate expression.
+ */
+public class BetweenPredicate extends Expression {
+
+    private boolean isNotBetween;

Review Comment:
   we should not include NOT here, but use NotExpression with BetweenPredicate as child



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/operators/plans/logical/LogicalAggregation.java:
##########
@@ -0,0 +1,75 @@
+// 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.operators.plans.logical;
+
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.operators.OperatorType;
+import org.apache.doris.nereids.trees.expressions.NamedExpression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.trees.plans.Plan;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Logical Aggregation plan operator.
+ */
+public class LogicalAggregation extends LogicalUnaryOperator {
+
+    private final List<? extends NamedExpression> aggregation;

Review Comment:
   i think we need to add group by expression here



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -162,7 +191,7 @@ public List<Expression> visitNamedExpressionSeq(NamedExpressionSeqContext ctx) {
         List<Expression> expressions = Lists.newArrayList();
         if (ctx != null) {
             for (NamedExpressionContext namedExpressionContext : ctx.namedExpression()) {
-                NamedExpression namedExpression = typedVisit(namedExpressionContext);
+                Expression namedExpression = typedVisit(namedExpressionContext);

Review Comment:
   👍🏻



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Arithmetic.java:
##########
@@ -0,0 +1,133 @@
+// 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;
+
+
+import org.apache.doris.nereids.trees.NodeType;
+import org.apache.doris.thrift.TExprOpcode;
+
+/**
+ * All arithmetic operator.
+ */
+public class Arithmetic<LEFT_CHILD_TYPE extends Expression, RIGHT_CHILD_TYPE extends Expression>
+        extends Expression implements BinaryExpression<LEFT_CHILD_TYPE, RIGHT_CHILD_TYPE> {
+
+    enum OperatorPosition {
+        BINARY_INFIX,
+        UNARY_PREFIX,
+        UNARY_POSTFIX,
+    }
+
+    /**
+     * All counts as expressions.
+     */
+    @SuppressWarnings("checkstyle:RegexpSingleline")
+    public enum Operator {
+        MULTIPLY("*", "multiply", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.MULTIPLY),
+        DIVIDE("/", "divide", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.DIVIDE),
+        MOD("%", "mod", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.MOD),
+        INT_DIVIDE("DIV", "int_divide", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.INT_DIVIDE),
+        ADD("+", "add", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.ADD),
+        SUBTRACT("-", "subtract", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.SUBTRACT),
+        BITAND("&", "bitand", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.BITAND),
+        BITOR("|", "bitor", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.BITOR),
+        BITXOR("^", "bitxor", Arithmetic.OperatorPosition.BINARY_INFIX, TExprOpcode.BITXOR),
+        BITNOT("~", "bitnot", Arithmetic.OperatorPosition.UNARY_PREFIX, TExprOpcode.BITNOT),
+        FACTORIAL("!", "factorial", Arithmetic.OperatorPosition.UNARY_POSTFIX, TExprOpcode.FACTORIAL);

Review Comment:
   these maybe a UnaryExpression? For the more, based on the previous discussion, we should break them down into separate expressions, should we @EmmyMiao87 ?



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -132,11 +153,18 @@ private LogicalPlan plan(ParserRuleContext tree) {
     public LogicalPlan visitQuery(QueryContext ctx) {
         Supplier<LogicalPlan> f = () -> {
             // TODO: need to add withQueryResultClauses and withCTE
-            return plan(ctx.queryTerm());
+            LogicalPlan query = plan(ctx.queryTerm());
+            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            return queryOrganization == null ? query : queryOrganization;

Review Comment:
   should we move this statement into withQueryOrganization



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -132,11 +153,18 @@ private LogicalPlan plan(ParserRuleContext tree) {
     public LogicalPlan visitQuery(QueryContext ctx) {
         Supplier<LogicalPlan> f = () -> {
             // TODO: need to add withQueryResultClauses and withCTE
-            return plan(ctx.queryTerm());
+            LogicalPlan query = plan(ctx.queryTerm());
+            LogicalPlan queryOrganization = withQueryOrganization(ctx.queryOrganization(), query);
+            return queryOrganization == null ? query : queryOrganization;
         };
         return ParserUtils.withOrigin(ctx, f);
     }
 
+    private LogicalPlan withQueryOrganization(QueryOrganizationContext ctx, LogicalPlan children) {
+        List<SortItems> sortItems = visitQueryOrganization(ctx);
+        return sortItems == null ? null : new LogicalUnaryPlan(new LogicalSort(sortItems), children);

Review Comment:
   maybe it is better
   ```suggestion
           return sortItems == null ? children : new LogicalUnaryPlan(new LogicalSort(sortItems), children);
   ```



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