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

[GitHub] [doris] YangShaw opened a new pull request, #11264: [feature](nereids)add InPredicate in expressions

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

   # Proposed changes
   
   ## Problem Summary:
   Add InPredicate expression parser
   ## Checklist(Required)
   
   1. Type of your changes: (Feature)
   2. Does it affect the original behavior: (No)
   3. Has unit tests been added: (Yes)
   4. Has document been added or modified: (No Need)
   5. Does it need to update dependencies: (No)
   6. 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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -838,4 +840,10 @@ public Expression visitSubqueryExpression(SubqueryExpressionContext subqueryExpr
     public Expression visitExist(ExistContext context) {
         return ParserUtils.withOrigin(context, () -> new Exists(typedVisit(context.query())));
     }
+
+    public List<Expression> withInList(PredicateContext ctx) {
+        List<Expression> expressions = ctx.expression().stream()
+                .map(expr -> getExpression(expr)).collect(ImmutableList.toImmutableList());
+        return expressions;

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;

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 #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,82 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = compareExpr;
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return optionsList.stream().map(Expression::nullable)
+            .reduce((a, b) -> a || b).get();
+    }
+
+    @Override
+    public String toString() {
+        return compareExpr + " IN " + optionsList.stream()
+            .map(Expression::toString)
+            .collect(Collectors.joining(",", "(", ")"));
+    }
+
+    @Override
+    public String toSql() {
+        return compareExpr.toSql() + " IN " + optionsList.stream()
+            .map(Expression::toSql)
+            .collect(Collectors.joining(",", "(", ")"));
+    }
+

Review Comment:
   You also need to add equals() and hashcode() here



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -782,8 +783,10 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
                     break;
                 case DorisParser.IN:
                     if (ctx.query() == null) {
-                        //TODO: InPredicate

Review Comment:
   Comments can be deleted



-- 
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 #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -783,7 +784,10 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
                 case DorisParser.IN:
                     if (ctx.query() == null) {
                         //TODO: InPredicate

Review Comment:
   Comments can be deleted



-- 
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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = Objects.requireNonNull(compareExpr, "Compare Expr cannot be null");
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return children().stream().anyMatch(Expression::nullable);
+    }
+
+    @Override
+    public String toString() {
+        return compareExpr + " IN " + optionsList.stream()
+            .map(Expression::toString)
+            .collect(Collectors.joining(",", "(", ")"));

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = Objects.requireNonNull(compareExpr, "Compare Expr cannot be null");
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return children().stream().anyMatch(Expression::nullable);
+    }
+
+    @Override
+    public String toString() {
+        return compareExpr + " IN " + optionsList.stream()
+            .map(Expression::toString)
+            .collect(Collectors.joining(",", "(", ")"));
+    }
+
+    @Override
+    public String toSql() {
+        return compareExpr.toSql() + " IN " + optionsList.stream()
+            .map(Expression::toSql)
+            .collect(Collectors.joining(",", "(", ")"));

Review Comment:
   done



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;

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 #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,82 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = compareExpr;

Review Comment:
   You can use Objects.requireNonNull to ensure that the parameter cannot be 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] 924060929 merged pull request #11264: [feature](nereids)add InPredicate in expressions

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


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

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


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


[GitHub] [doris] 924060929 commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,82 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = Objects.requireNonNull(compareExpr, "Compare Expr cannot be null");
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return optionsList.stream().map(Expression::nullable)
+            .reduce((a, b) -> a || b).get();

Review Comment:
   InPredicate is nullable if compareExpr is nullable?
   ```suggestion
           return children().stream().anyMatch(Expression::nullable);
   ```



-- 
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 #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:
##########
@@ -141,10 +145,48 @@ public Expr visitNullSafeEqual(NullSafeEqual nullSafeEqual, PlanTranslatorContex
 
     @Override
     public Expr visitNot(Not not, PlanTranslatorContext context) {
-        return new org.apache.doris.analysis.CompoundPredicate(
-                org.apache.doris.analysis.CompoundPredicate.Operator.NOT,
-                not.child(0).accept(this, context),
-                null);
+        if (not.child() instanceof InPredicate) {
+            InPredicate inPredicate = (InPredicate) not.child();
+            List<Expr> inList = inPredicate.getOptions().stream()
+                    .map(e -> translate(e, context))
+                    .collect(Collectors.toList());
+            return new org.apache.doris.analysis.InPredicate(
+                    inPredicate.getCompareExpr().accept(this, context),
+                    inList,
+                    true);
+        } else if (not.child() instanceof Like) {
+            Like like = (Like) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitLike(like, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;
+        } else if (not.child() instanceof Regexp) {
+            Regexp regexp = (Regexp) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitRegexp(regexp, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;
+        } else if (not.child() instanceof Between) {
+            Between between = (Between) not.child();
+            BetweenPredicate betweenPredicate = new BetweenPredicate(
+                    between.getCompareExpr().accept(this, context),
+                    between.getLowerBound().accept(this, context),
+                    between.getUpperBound().accept(this, context),
+                    true);
+            return betweenPredicate;

Review Comment:
   we cannot meet between when we do expression translate



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:
##########
@@ -141,10 +145,48 @@ public Expr visitNullSafeEqual(NullSafeEqual nullSafeEqual, PlanTranslatorContex
 
     @Override
     public Expr visitNot(Not not, PlanTranslatorContext context) {
-        return new org.apache.doris.analysis.CompoundPredicate(
-                org.apache.doris.analysis.CompoundPredicate.Operator.NOT,
-                not.child(0).accept(this, context),
-                null);
+        if (not.child() instanceof InPredicate) {
+            InPredicate inPredicate = (InPredicate) not.child();
+            List<Expr> inList = inPredicate.getOptions().stream()
+                    .map(e -> translate(e, context))
+                    .collect(Collectors.toList());
+            return new org.apache.doris.analysis.InPredicate(
+                    inPredicate.getCompareExpr().accept(this, context),
+                    inList,
+                    true);
+        } else if (not.child() instanceof Like) {
+            Like like = (Like) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitLike(like, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;
+        } else if (not.child() instanceof Regexp) {
+            Regexp regexp = (Regexp) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitRegexp(regexp, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;

Review Comment:
   could merge into else?



-- 
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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,82 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = compareExpr;
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return optionsList.stream().map(Expression::nullable)
+            .reduce((a, b) -> a || b).get();
+    }
+
+    @Override
+    public String toString() {
+        return compareExpr + " IN " + optionsList.stream()
+            .map(Expression::toString)
+            .collect(Collectors.joining(",", "(", ")"));
+    }
+
+    @Override
+    public String toSql() {
+        return compareExpr.toSql() + " IN " + optionsList.stream()
+            .map(Expression::toSql)
+            .collect(Collectors.joining(",", "(", ")"));
+    }
+

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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;

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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:
##########
@@ -141,10 +145,48 @@ public Expr visitNullSafeEqual(NullSafeEqual nullSafeEqual, PlanTranslatorContex
 
     @Override
     public Expr visitNot(Not not, PlanTranslatorContext context) {
-        return new org.apache.doris.analysis.CompoundPredicate(
-                org.apache.doris.analysis.CompoundPredicate.Operator.NOT,
-                not.child(0).accept(this, context),
-                null);
+        if (not.child() instanceof InPredicate) {
+            InPredicate inPredicate = (InPredicate) not.child();
+            List<Expr> inList = inPredicate.getOptions().stream()
+                    .map(e -> translate(e, context))
+                    .collect(Collectors.toList());
+            return new org.apache.doris.analysis.InPredicate(
+                    inPredicate.getCompareExpr().accept(this, context),
+                    inList,
+                    true);
+        } else if (not.child() instanceof Like) {
+            Like like = (Like) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitLike(like, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;
+        } else if (not.child() instanceof Regexp) {
+            Regexp regexp = (Regexp) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitRegexp(regexp, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;
+        } else if (not.child() instanceof Between) {
+            Between between = (Between) not.child();
+            BetweenPredicate betweenPredicate = new BetweenPredicate(
+                    between.getCompareExpr().accept(this, context),
+                    between.getLowerBound().accept(this, context),
+                    between.getUpperBound().accept(this, context),
+                    true);
+            return betweenPredicate;

Review Comment:
   Yes, I have realized this after ran some queries. I will delete this case and reset visitBetween later.



-- 
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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/ExpressionTranslator.java:
##########
@@ -141,10 +145,48 @@ public Expr visitNullSafeEqual(NullSafeEqual nullSafeEqual, PlanTranslatorContex
 
     @Override
     public Expr visitNot(Not not, PlanTranslatorContext context) {
-        return new org.apache.doris.analysis.CompoundPredicate(
-                org.apache.doris.analysis.CompoundPredicate.Operator.NOT,
-                not.child(0).accept(this, context),
-                null);
+        if (not.child() instanceof InPredicate) {
+            InPredicate inPredicate = (InPredicate) not.child();
+            List<Expr> inList = inPredicate.getOptions().stream()
+                    .map(e -> translate(e, context))
+                    .collect(Collectors.toList());
+            return new org.apache.doris.analysis.InPredicate(
+                    inPredicate.getCompareExpr().accept(this, context),
+                    inList,
+                    true);
+        } else if (not.child() instanceof Like) {
+            Like like = (Like) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitLike(like, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;
+        } else if (not.child() instanceof Regexp) {
+            Regexp regexp = (Regexp) not.child();
+            LikePredicate likePredicate = (LikePredicate) visitRegexp(regexp, context);
+            CompoundPredicate compoundPredicate = new CompoundPredicate(CompoundPredicate.Operator.NOT,
+                    likePredicate,
+                    null);
+            return compoundPredicate;

Review Comment:
   I will have a try.



-- 
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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,82 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = Objects.requireNonNull(compareExpr, "Compare Expr cannot be null");
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return optionsList.stream().map(Expression::nullable)
+            .reduce((a, b) -> a || b).get();

Review Comment:
   Yes, I missed it. Have fixed.



-- 
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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -798,9 +799,10 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
                     break;
                 case DorisParser.IN:
                     if (ctx.query() == null) {
-                        //TODO: InPredicate
-                        outExpression = null;
-                        throw new IllegalStateException("Unsupported predicate type: " + ctx.kind.getText());
+                        outExpression = new InPredicate(
+                            valueExpression,
+                            withInList(ctx)

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] wangshuo128 commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;

Review Comment:
   ```suggestion
       private final Expression compareExpr;
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = Objects.requireNonNull(compareExpr, "Compare Expr cannot be null");
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return children().stream().anyMatch(Expression::nullable);
+    }
+
+    @Override
+    public String toString() {
+        return compareExpr + " IN " + optionsList.stream()
+            .map(Expression::toString)
+            .collect(Collectors.joining(",", "(", ")"));
+    }
+
+    @Override
+    public String toSql() {
+        return compareExpr.toSql() + " IN " + optionsList.stream()
+            .map(Expression::toSql)
+            .collect(Collectors.joining(",", "(", ")"));

Review Comment:
   ```suggestion
               .collect(Collectors.joining(", ", "(", ")"));
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;

Review Comment:
   ```suggestion
       private List<Expression> options;
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = Objects.requireNonNull(compareExpr, "Compare Expr cannot be null");
+        this.optionsList = ImmutableList.copyOf(Objects.requireNonNull(optionsList, "In list cannot be null"));
+    }
+
+    public <R, C> R accept(ExpressionVisitor<R, C> visitor, C context) {
+        return visitor.visitInPredicate(this, context);
+    }
+
+    @Override
+    public DataType getDataType() throws UnboundException {
+        return BooleanType.INSTANCE;
+    }
+
+    @Override
+    public boolean nullable() throws UnboundException {
+        return children().stream().anyMatch(Expression::nullable);
+    }
+
+    @Override
+    public String toString() {
+        return compareExpr + " IN " + optionsList.stream()
+            .map(Expression::toString)
+            .collect(Collectors.joining(",", "(", ")"));

Review Comment:
   ```suggestion
               .collect(Collectors.joining(", ", "(", ")"));
   ```



-- 
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 #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -798,9 +799,10 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
                     break;
                 case DorisParser.IN:
                     if (ctx.query() == null) {
-                        //TODO: InPredicate
-                        outExpression = null;
-                        throw new IllegalStateException("Unsupported predicate type: " + ctx.kind.getText());
+                        outExpression = new InPredicate(
+                            valueExpression,
+                            withInList(ctx)

Review Comment:
   nit: we need 8 indent
   ```suggestion
                                   valueExpression,
                                   withInList(ctx)
   ```



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,99 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;

Review Comment:
   final



##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -838,4 +840,10 @@ public Expression visitSubqueryExpression(SubqueryExpressionContext subqueryExpr
     public Expression visitExist(ExistContext context) {
         return ParserUtils.withOrigin(context, () -> new Exists(typedVisit(context.query())));
     }
+
+    public List<Expression> withInList(PredicateContext ctx) {
+        List<Expression> expressions = ctx.expression().stream()
+                .map(expr -> getExpression(expr)).collect(ImmutableList.toImmutableList());
+        return expressions;

Review Comment:
   ```suggestion
           return ctx.expression().stream()
                   .map(this::getExpression).collect(ImmutableList.toImmutableList());
   ```



-- 
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 #11264: [feature](nereids)add InPredicate in expressions

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

   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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,82 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = compareExpr;

Review Comment:
   Have added requireNonNull() for compareExpr



-- 
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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/InPredicate.java:
##########
@@ -0,0 +1,82 @@
+// 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.expressions.visitor.ExpressionVisitor;
+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;
+import java.util.stream.Collectors;
+
+/**
+ * In predicate expression.
+ */
+public class InPredicate extends Expression {
+
+    private Expression compareExpr;
+    private List<Expression> optionsList;
+
+    public InPredicate(Expression compareExpr, List<Expression> optionsList) {
+        super(new Builder<Expression>().add(compareExpr).addAll(optionsList).build().toArray(new Expression[0]));
+        this.compareExpr = compareExpr;

Review Comment:
   Has added requireNonNull() for compareExpr



-- 
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] YangShaw commented on a diff in pull request #11264: [feature](nereids)add InPredicate in expressions

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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java:
##########
@@ -783,7 +784,10 @@ private Expression withPredicate(Expression valueExpression, PredicateContext ct
                 case DorisParser.IN:
                     if (ctx.query() == null) {
                         //TODO: InPredicate

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