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/24 04:43:36 UTC

[GitHub] [doris] morrySnow commented on a diff in pull request #10377: [feature](nereids) Add brackets expr and ssbSql and inPredicate Expr

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -562,6 +567,21 @@ public Expression withBetween(PredicateContext ctx, Expression e) {
         return isNotBetween ? new Not(betweenPredicate) : betweenPredicate;
     }
 
+    /**
+     * Generate In predicate.
+     *
+     * @param ctx PredicateContext
+     * @param e Expression
+     * @return Expression
+     */
+    public Expression withIn(PredicateContext ctx, Expression e) {
+        boolean isNotIn = ctx.NOT() != null ? true : false;

Review Comment:
   process NOT in withPredicate is better



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,64 @@
+// 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.trees.NodeType;
+import org.apache.doris.nereids.types.BooleanType;
+import org.apache.doris.nereids.types.DataType;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * In Predicate Expression.
+ */
+public class InPredicate extends Expression {
+    private Expression compareExpression;
+    private List<Expression> inExpressions;
+
+    public InPredicate(Expression compareExpression, List<Expression> inExpressions) {
+        super(NodeType.IN,
+                (new Builder<Expression>().add(compareExpression).addAll(inExpressions)
+                        .build().toArray(new Expression[0])));
+        this.compareExpression = compareExpression;
+        this.inExpressions = ImmutableList.copyOf(Objects.requireNonNull(inExpressions, "in list can not be null"));
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public String sql() {
+        String sql = "";
+        for (Expression expression : inExpressions) {
+            sql += expression.sql();
+            sql += ", ";
+        }
+        return compareExpression.sql() + " IN " + sql;
+    }

Review Comment:
   return string is not a valid sql.
   ```suggestion
       public String sql() {
           return compareExpression.sql() + " IN " + expressions.stream()
                       .map(Expression::sql)
                       .collect(Collectors.joining(", ", "(", ")"));
       }
   ```



##########
fe/fe-core/src/test/java/org/apache/doris/nereids/trees/expressions/ExpressionParserTest.java:
##########
@@ -134,4 +134,10 @@ public void testSortClause() throws Exception {
         String sort1 = "select a from test order by 1";
         assertSql(sort1);
     }
+
+    @Test
+    public void testBrackets() throws Exception {
+        String brackets = "select * from t1 where (a = 1) and (b = 1)";
+        assertSql(brackets);

Review Comment:
   just notice print in assertXXX method, i think we should remove these print.



##########
fe/fe-core/src/test/java/org/apache/doris/nereids/SsbTest.java:
##########
@@ -0,0 +1,63 @@
+// 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;
+
+import org.apache.doris.nereids.parser.SqlParser;
+import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+public class SsbTest extends TestWithFeService {

Review Comment:
   do we need fe service to test parser?
   start a fe service is vary expensive.
   in Nereids's test, we should try to avoid to do that.



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