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/01 13:12:44 UTC

[GitHub] [incubator-doris] xinghuayu007 opened a new pull request #5436: [FEATURE]Check date type to avoid scan all partitions

xinghuayu007 opened a new pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436


   ## Proposed changes
   
   select day from test where day='2020-10-32', table 'test' is parititioned by day. In this case, '2020-10-32' will be taken as CastExpr not LiteralExpr, and condition "day='2020-10-32'" will not be recognized as partitionfilter. This case will scan all partitions. To avoid scall all partitions, it is better to filter invalid date value.
   
   New addition: A datetime with micro second will be parsed into second.
   
   issue: #4755
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [] Bugfix (non-breaking change which fixes an issue)
   - [x] New feature (non-breaking change which adds functionality)
   - [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [] Documentation Update (if none of the other choices apply)
   - [] Code refactor (Modify the code structure, format the code, etc...)
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [] I have created an issue on (Fix #ISSUE) and described the bug/feature there in detail
   - [] Compiling and unit tests pass locally with my changes
   - [] I have added tests that prove my fix is effective or that my feature works
   - [] If these changes need document changes, I have updated the document
   - [] Any dependent changes have been merged
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at 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.

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] [incubator-doris] kangkaisen commented on a change in pull request #5436: [FEATURE]Check date type to avoid scan all partitions

Posted by GitBox <gi...@apache.org>.
kangkaisen commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r589124122



##########
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:
       I mean null Literal.




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


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

Posted by GitBox <gi...@apache.org>.
kangkaisen commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r589123968



##########
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:
       OK,Add this to comment.




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


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

Posted by GitBox <gi...@apache.org>.
kangkaisen commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r598078226



##########
File path: fe/fe-core/src/main/java/org/apache/doris/rewrite/SimplifyInvalidDateBinaryPredicatesDateRule.java
##########
@@ -0,0 +1,54 @@
+// 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.NullLiteral;
+import org.apache.doris.common.AnalysisException;
+
+/**
+ * this rule try to convert date expression, if date is invalid, it will be
+ * converted into null literal to avoid to scan all partitions
+ * 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' && 'yyyyMMdd'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.
+ * Examples:
+ * date = "2020-10-32" => FALSE
+ */
+public class SimplifyInvalidDateBinaryPredicatesDateRule implements ExprRewriteRule {
+    public static ExprRewriteRule INSTANCE = new SimplifyInvalidDateBinaryPredicatesDateRule();
+
+    @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()

Review comment:
       This logic isn't right, If the DateLiteral format is  'yyyy-MM-dd hh', you will get the wrong result.




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


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

Posted by GitBox <gi...@apache.org>.
kangkaisen commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r586167698



##########
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:
       You should return null, not 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:
users@infra.apache.org



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


[GitHub] [incubator-doris] xinghuayu007 closed pull request #5436: [FEATURE]Check date type to avoid scan all partitions

Posted by GitBox <gi...@apache.org>.
xinghuayu007 closed pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436


   


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


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

Posted by GitBox <gi...@apache.org>.
xinghuayu007 commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r589146139



##########
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:
       done
   

##########
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:
       done

##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
##########
@@ -253,6 +253,11 @@ public static DateLiteral createMinValue(Type type) throws AnalysisException {
     }
 
     private void init(String s, Type type) throws AnalysisException {
+        // if s contains micro seconds, split it and only maintain second part
+        // because BE only save a datetime with second part
+        if (s.length() > 19) {

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.

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] [incubator-doris] kangkaisen commented on a change in pull request #5436: [FEATURE]Check date type to avoid scan all partitions

Posted by GitBox <gi...@apache.org>.
kangkaisen commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r586167242



##########
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:
       Why not check the 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


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

Posted by GitBox <gi...@apache.org>.
kangkaisen commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r586166167



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

Review comment:
       ```suggestion
   public class SimplifyInvalidDateBinaryPredicatesDateRule implements ExprRewriteRule {
   ```




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


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

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r592403731



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
##########
@@ -144,6 +144,8 @@
 
     //Regex used to determine if the TIME field exists int date_format
     private static final Pattern HAS_TIME_PART = Pattern.compile("^.*[HhIiklrSsTp]+.*$");
+    // max length of datetime string
+    int MAX_DATETIME_VALUE_LENGTH = new String("yyyy-MM-dd hh:mm:ss").length();

Review comment:
       missing `private static final`?




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


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

Posted by GitBox <gi...@apache.org>.
xinghuayu007 commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r598409824



##########
File path: fe/fe-core/src/main/java/org/apache/doris/rewrite/SimplifyInvalidDateBinaryPredicatesDateRule.java
##########
@@ -0,0 +1,54 @@
+// 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.NullLiteral;
+import org.apache.doris.common.AnalysisException;
+
+/**
+ * this rule try to convert date expression, if date is invalid, it will be
+ * converted into null literal to avoid to scan all partitions
+ * 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' && 'yyyyMMdd'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.
+ * Examples:
+ * date = "2020-10-32" => FALSE
+ */
+public class SimplifyInvalidDateBinaryPredicatesDateRule implements ExprRewriteRule {
+    public static ExprRewriteRule INSTANCE = new SimplifyInvalidDateBinaryPredicatesDateRule();
+
+    @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()

Review comment:
       Yes. That is because Class DateLiteral only try to parse format 'yyyy-MM-dd hh:ss:ii', not try to parse format 'yyyy-MM-dd hh'. And another problem can not be solved. When a datetime contains mircosecond like a > '2020-12-12 12:12:12. 111'. It should be rewrited into a >=  '2020-12-12 12:12:13'. I will find a better solution.




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


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

Posted by GitBox <gi...@apache.org>.
xinghuayu007 commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r594011337



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
##########
@@ -144,6 +144,8 @@
 
     //Regex used to determine if the TIME field exists int date_format
     private static final Pattern HAS_TIME_PART = Pattern.compile("^.*[HhIiklrSsTp]+.*$");
+    // max length of datetime string
+    int MAX_DATETIME_VALUE_LENGTH = new String("yyyy-MM-dd hh:mm:ss").length();

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.

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] [incubator-doris] xinghuayu007 commented on a change in pull request #5436: [FEATURE]Check date type to avoid scan all partitions

Posted by GitBox <gi...@apache.org>.
xinghuayu007 commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r588985998



##########
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:
       return null will cause NullPointException:
   java.lang.NullPointerException: null
   	at org.apache.doris.rewrite.ExprRewriter.applyRuleBottomUp(ExprRewriter.java:82) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.rewrite.ExprRewriter.applyRuleRepeatedly(ExprRewriter.java:71) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.rewrite.ExprRewriter.rewrite(ExprRewriter.java:55) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.analysis.SelectStmt.rewriteExprs(SelectStmt.java:1424) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.qe.StmtExecutor.analyzeAndGenerateQueryPlan(StmtExecutor.java:514) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.qe.StmtExecutor.analyze(StmtExecutor.java:475) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:272) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.qe.StmtExecutor.execute(StmtExecutor.java:243) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.qe.ConnectProcessor.handleQuery(ConnectProcessor.java:199) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.qe.ConnectProcessor.dispatch(ConnectProcessor.java:337) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.qe.ConnectProcessor.processOnce(ConnectProcessor.java:535) ~[palo-fe.jar:3.4.0]
   	at org.apache.doris.mysql.nio.ReadListener.lambda$handleEvent$0(ReadListener.java:50) ~[palo-fe.jar:3.4.0]
   	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_231]
   	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_231]
   	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_231]
   




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


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

Posted by GitBox <gi...@apache.org>.
acelyc111 commented on a change in pull request #5436:
URL: https://github.com/apache/incubator-doris/pull/5436#discussion_r589135143



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/DateLiteral.java
##########
@@ -253,6 +253,11 @@ public static DateLiteral createMinValue(Type type) throws AnalysisException {
     }
 
     private void init(String s, Type type) throws AnalysisException {
+        // if s contains micro seconds, split it and only maintain second part
+        // because BE only save a datetime with second part
+        if (s.length() > 19) {

Review comment:
       `19` is a magic number, how about define a member variable like `MAX_DATE_VALUE_LENGTH = new String("yyyy-MM-dd hh:mm:ss").length();` ?




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


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

Posted by GitBox <gi...@apache.org>.
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