Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1a15f53
udf: replace function
Aug 13, 2020
7d072b9
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 14, 2020
391158f
udf: replace function
Aug 14, 2020
5eb52e1
udf: replace function
Aug 14, 2020
a79ea91
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 18, 2020
86f841f
udf: replace function
Aug 18, 2020
ade1afa
udf: replace function
Aug 18, 2020
1d95a49
udf: replace function
Aug 18, 2020
433eb87
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 24, 2020
c62d239
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 25, 2020
0a8db8c
Merge remote-tracking branch 'upstream/master' into str_replace
Aug 25, 2020
02d3f86
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 1, 2020
41da0ba
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 8, 2020
de4e523
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 11, 2020
a863b0d
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 17, 2020
024c422
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 22, 2020
e1656c7
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 23, 2020
837e037
Merge remote-tracking branch 'upstream/master' into str_replace
Sep 27, 2020
a36d3e7
Merge remote-tracking branch 'upstream/master' into str_replace
Oct 17, 2020
33af93f
check invalid date type
Oct 17, 2020
ab58cbd
Check date type to avoid scan all partitions
Oct 17, 2020
1ef7fb8
update
Oct 22, 2020
92ee1af
update
Oct 22, 2020
c5ef96e
update
Oct 22, 2020
8737818
update
Oct 22, 2020
9a30247
update
Oct 23, 2020
5fd1500
Merge remote-tracking branch 'upstream/master' into check_datetime
Oct 23, 2020
a4bdbcd
update
Oct 23, 2020
99f6e30
Merge remote-tracking branch 'upstream/master' into check_datetime
Oct 27, 2020
1736f13
update
Nov 1, 2020
685a7bf
update
Nov 1, 2020
7b2d36d
update
Nov 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.doris.rewrite.mvrewrite.HLLHashToSlotRefRule;
import org.apache.doris.rewrite.mvrewrite.NDVToHll;
import org.apache.doris.rewrite.mvrewrite.ToBitmapToSlotRefRule;
import org.apache.doris.rewrite.BinaryPredicatesDateRule;
import org.apache.doris.thrift.TQueryGlobals;

import com.google.common.base.Joiner;
Expand Down Expand Up @@ -255,6 +256,7 @@ public GlobalState(Catalog catalog, ConnectContext context) {
// pushdown and Parquet row group pruning based on min/max statistics.
rules.add(NormalizeBinaryPredicatesRule.INSTANCE);
rules.add(FoldConstantsRule.INSTANCE);
rules.add(BinaryPredicatesDateRule.INSTANCE);
exprRewriter_ = new ExprRewriter(rules);
// init mv rewriter
List<ExprRewriteRule> mvRewriteRules = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
return expr;
}
}
63 changes: 63 additions & 0 deletions fe/fe-core/src/test/java/org/apache/doris/planner/QueryPlanTest.java
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,69 @@ public void testIntDateTime() throws Exception {
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `date` IN ('2020-10-30 00:00:00')"));
}

@Test
public void testCheckInvalidDate() throws Exception {
FeConstants.runningUnitTest = true;
connectContext.setDatabase("default_cluster:test");
//valid date
String sql = "select day from tbl_int_date where day = '2020-10-30'";
String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `day` = '2020-10-30 00:00:00'"));
//valid date
sql = "select day from tbl_int_date where day = 20201030";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `day` = '2020-10-30 00:00:00'"));
//invalid date
sql = "select day from tbl_int_date where day = '2020-10-32'";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
System.out.println(explainString);
Assert.assertTrue(explainString.contains("EMPTYSET"));
//invalid date
sql = "select day from tbl_int_date where day = 'hello'";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("EMPTYSET"));
//invalid date
sql = "select day from tbl_int_date where day = 2020-10-30";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
//invalid date
sql = "select day from tbl_int_date where day = 10-30";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("EMPTYSET"));

//valid datetime
sql = "select day from tbl_int_date where date = '2020-10-30 12:12:30'";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 12:12:30'"));
//valid datetime
sql = "select day from tbl_int_date where date = 20201030";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 00:00:00'"));
//valid datetime
sql = "select day from tbl_int_date where date = '2020-10-30'";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("PREDICATES: `date` = '2020-10-30 00:00:00'"));
//invalid datetime
sql = "select day from tbl_int_date where date = '2020-10-32'";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("EMPTYSET"));
//invalid datetime
sql = "select day from tbl_int_date where date = 'hello'";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("EMPTYSET"));
//invalid datetime
sql = "select day from tbl_int_date where date = 2020-10-30";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("EMPTYSET"));
//invalid datetime
sql = "select day from tbl_int_date where date = 10-30";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("EMPTYSET"));
//invalid datetime
sql = "select day from tbl_int_date where date = '2020-10-12 12:23:76'";
explainString = UtFrameUtils.getSQLPlanOrErrorMsg(connectContext, "EXPLAIN " + sql);
Assert.assertTrue(explainString.contains("EMPTYSET"));
}
}