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 2021/03/07 07:20:48 UTC

[GitHub] [incubator-doris] xinghuayu007 commented on a change in pull request #5436: [FEATURE]Check date type to avoid scan all partitions

xinghuayu007 commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r588985930



##########
File path: fe/fe-core/src/main/java/org/apache/doris/rewrite/BinaryPredicatesDateRule.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.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.common.AnalysisException;
+
+/**
+ * Binary predicate date rule try to convert date expression, if date is invalid, it will be
+ * converted 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 lchild = expr.getChild(0);
+        if (!lchild.getType().isDateType()) {
+            return expr;
+        }
+        Expr valueExpr = expr.getChild(1);
+        if(valueExpr.getType().isDateType() && valueExpr.isConstant()
+                && valueExpr instanceof CastExpr) {
+            return new BoolLiteral(false);

Review comment:
       In Classs DateLiteral, FE uses joda time library to parse a date value. FE only supports 'yyyy-MM-dd hh:mm:ss' && 'yyyy-MM-dd' format, so if FE unchecked cast fail, it also builds CastExpr for BE. Therefore, if a Expr is CastExpr, it should be invalid date value.




----------------------------------------------------------------
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:
users@infra.apache.org



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