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

[GitHub] [doris] morrySnow commented on a diff in pull request #14867: [feature](nereids)add binary & unary arithmetic for nereids

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:
##########
@@ -346,6 +347,12 @@ public Expr visitBinaryArithmetic(BinaryArithmetic binaryArithmetic, PlanTransla
                 binaryArithmetic.child(1).accept(this, context));
     }
 
+    @Override
+    public Expr visitUnaryArithmetic(UnaryArithmetic unaryArithmetic, PlanTranslatorContext context) {

Review Comment:
   add a translator UT, we need to build translator UT from now on



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -493,12 +497,15 @@ public Expression visitPredicated(PredicatedContext ctx) {
     @Override
     public Expression visitArithmeticUnary(ArithmeticUnaryContext ctx) {
         return ParserUtils.withOrigin(ctx, () -> {
-            Expression e = getExpression(ctx);
+            Expression e = typedVisit(ctx.getChild(1));

Review Comment:
   ```suggestion
               Expression e = typedVisit(ctx.valueExpression());
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/BitNot.java:
##########
@@ -0,0 +1,59 @@
+// 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.analysis.ArithmeticExpr.Operator;
+import org.apache.doris.nereids.exceptions.UnboundException;
+import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
+import org.apache.doris.nereids.types.DataType;
+import org.apache.doris.nereids.types.coercion.AbstractDataType;
+
+import com.google.common.base.Preconditions;
+
+import java.util.List;
+
+/**
+ * bit not
+ */
+public class BitNot extends UnaryArithmetic {
+
+    public BitNot(Expression child) {
+        super(child, Operator.BITNOT);
+    }
+
+    @Override
+    public Expression withChildren(List<Expression> children) {
+        Preconditions.checkArgument(children.size() == 1);
+        return new BitNot(child());
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return child().getDataType();
+    }
+
+    @Override
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitBitNot(this, context);
+    }
+
+    @Override
+    public AbstractDataType inputType() {
+        return child().getDataType();

Review Comment:
   input type is used to declare valid input type see more detail in `org.apache.doris.nereids.trees.expressions.Multiply`



##########
regression-test/suites/nereids_syntax_p0/unary_binary_arithmetic.groovy:
##########
@@ -0,0 +1,44 @@
+// 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.
+
+suite("unary_binary_arithmetic") {
+    sql "set enable_nereids_planner=true"
+    sql "set enable_fallback_to_original_planner=false"
+
+    qt_select "select 8 div 2";
+    
+    qt_select "select 7 & 1";
+    qt_select "select 4 & 1";
+    
+    qt_select "select 7 ^ 7"
+    qt_select "select 7 ^ 8"
+
+    qt_select "select 3 | 4"
+    qt_select "select 7 | 0"
+
+    qt_select "select 4 % 2"
+    qt_select "select 99 % 2"
+
+    qt_select "select -1"
+    qt_select "select -(2+3)"
+    qt_select "select +(1+1)"
+    qt_select "select ~7"
+    qt_select "select ~8"

Review Comment:
   add some invalid sql, and check whether we can get expected exception 



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