xy720 commented on a change in pull request #4756:
URL: https://github.com/apache/incubator-doris/pull/4756#discussion_r510165496



##########
File path: 
fe/fe-core/src/main/java/org/apache/doris/rewrite/BinaryPredicatesDateRule.java
##########
@@ -0,0 +1,46 @@
+// 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.rewrite;
+
+import org.apache.doris.analysis.Analyzer;
+import org.apache.doris.analysis.BinaryPredicate;
+import org.apache.doris.analysis.CastExpr;
+import org.apache.doris.analysis.Expr;
+import org.apache.doris.analysis.BoolLiteral;
+import org.apache.doris.catalog.Type;
+import org.apache.doris.common.AnalysisException;
+
+/**
+ * Binary predicaate date rule try to convert date expression, if date is 
invalid, it will be
+ * convert into bool literal to avoid to scan all partitions
+ * Examples:
+ * date = "2020-10-32" => FALSE
+ */
+public class BinaryPredicatesDateRule implements ExprRewriteRule {
+    public static ExprRewriteRule INSTANCE = new BinaryPredicatesDateRule();
+
+    @Override
+    public Expr apply(Expr expr, Analyzer analyzer) throws AnalysisException {
+        if (!(expr instanceof BinaryPredicate)) return expr;
+        Expr valueExpr = expr.getChild(1);
+        if(valueExpr.getType() == Type.DATETIME && valueExpr instanceof 
CastExpr) {

Review comment:
       ```suggestion
           if(valueExpr.getType() == Type.DATETIME && valueExpr instanceof 
CastExpr && valueExpr.getChild(0).getType() == Type.VARCHAR) {
   ```
   There is something wrong with this If statement.
   For example, `where day = 20201030` will rewrite to `where false`, which is 
not right.
   You should only support covert StringLiteral now:
   `where day = '20201032'` -> `where false`




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

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to