morrySnow commented on code in PR #31538:
URL: https://github.com/apache/doris/pull/31538#discussion_r1507178727
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyRange.java:
##########
@@ -65,12 +65,12 @@
* a in (1,2,3) and a in (4,5,6) => false
* The logic is as follows:
* 1. for `And` expression.
- * 1. extract conjunctions then build `ValueDesc` for each conjunction
- * 2. grouping according to `reference`, `ValueDesc` in the same group can
perform intersect
- * for example:
- * a > 1 and a > 2
- * 1. a > 1 => RangeValueDesc((1...+∞)), a > 2 => RangeValueDesc((2...+∞))
- * 2. (1...+∞) intersect (2...+∞) => (2...+∞)
+ * 1. extract conjunctions then build `ValueDesc` for each conjunction
+ * 2. grouping according to `reference`, `ValueDesc` in the same group can
perform intersect
+ * for example:
+ * a > 1 and a > 2
+ * 1. a > 1 => RangeValueDesc((1...+∞)), a > 2 => RangeValueDesc((2...+∞))
+ * 2. (1...+∞) intersect (2...+∞) => (2...+∞)
Review Comment:
add back Indentation
##########
regression-test/suites/nereids_rules_p0/mv/dimension_equal/filter_equal_or_notequal.groovy:
##########
@@ -158,132 +158,132 @@ suite("filter_equal_or_notequal_case") {
where l_shipdate = '2023-10-17'
"""
- create_mv_lineitem(mv_name, mtmv_sql)
- def job_name = getJobName(db, mv_name)
- waitingMTMVTaskFinished(job_name)
-
- // mv equal and sql equal
- def query_sql = """
- select l_shipdate, o_orderdate, l_partkey, l_suppkey
- from lineitem_1
- left join orders_1
- on lineitem_1.l_orderkey = orders_1.o_orderkey
- where l_shipdate = '2023-10-17'
- """
- def res_tmp = sql """explain ${query_sql}"""
- logger.info("res_temp:" + res_tmp)
- explain {
- sql("${query_sql}")
- contains "${mv_name}(${mv_name})"
- }
- compare_res(query_sql + " order by 1,2,3,4")
-
- // mv equal and sql not equal
- query_sql = """
- select l_shipdate, o_orderdate, l_partkey, l_suppkey
- from lineitem_1
- left join orders_1
- on lineitem_1.l_orderkey = orders_1.o_orderkey
- where l_shipdate != '2023-10-17'
- """
- explain {
- sql("${query_sql}")
- notContains "${mv_name}(${mv_name})"
- }
-
- // mv equal and sql equal and number is difference
- query_sql = """
- select l_shipdate, o_orderdate, l_partkey, l_suppkey
- from lineitem_1
- left join orders_1
- on lineitem_1.l_orderkey = orders_1.o_orderkey
- where l_shipdate = '2023-10-19'
- """
- explain {
- sql("${query_sql}")
- notContains "${mv_name}(${mv_name})"
- }
-
- mtmv_sql = """
- select l_shipdate, o_orderdate, l_partkey, l_suppkey, o_orderkey
- from lineitem_1
- left join orders_1
- on lineitem_1.l_orderkey = orders_1.o_orderkey
- where l_shipdate != '2023-10-17'
- """
-
- create_mv_lineitem(mv_name, mtmv_sql)
- job_name = getJobName(db, mv_name)
- waitingMTMVTaskFinished(job_name)
-
- // mv not equal and sql equal
- query_sql = """
- select l_shipdate, o_orderdate, l_partkey, l_suppkey
- from lineitem_1
- left join orders_1
- on lineitem_1.l_orderkey = orders_1.o_orderkey
- where l_shipdate = '2023-10-17'
- """
- explain {
- sql("${query_sql}")
- notContains "${mv_name}(${mv_name})"
- }
-
- // mv not equal and sql not equal
- query_sql = """
- select l_shipdate, o_orderdate, l_partkey, l_suppkey
- from lineitem_1
- left join orders_1
- on lineitem_1.l_orderkey = orders_1.o_orderkey
- where l_shipdate != '2023-10-17'
- """
- explain {
- sql("${query_sql}")
- contains "${mv_name}(${mv_name})"
- }
- compare_res(query_sql + " order by 1,2,3,4")
-
-
+// create_mv_lineitem(mv_name, mtmv_sql)
Review Comment:
why comment these cases?
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/SimplifyRangeTest.java:
##########
@@ -158,6 +164,72 @@ public void testSimplify() {
}
+ @Test
+ public void testSimplifyDate() {
+ executor = new
ExpressionRuleExecutor(ImmutableList.of(SimplifyRange.INSTANCE));
+ // assertRewrite("TA", "TA");
+ assertRewrite(
+ "(TA >= date '2024-01-01' and TA <= date '2024-01-03') or (TA
> date '2024-01-05' and TA < date '2024-01-07')",
+ "(TA >= date '2024-01-01' and TA <= date '2024-01-03') or (TA
> date '2024-01-05' and TA < date '2024-01-07')");
+ assertRewrite(
+ "(TA > date '2024-01-03' and TA < date '2024-01-01') or (TA >
date '2024-01-07'and TA < date '2024-01-05')",
+ "FALSE");
+ assertRewrite("TA > date '2024-01-03' and TA < date '2024-01-01'",
"FALSE");
+ assertRewrite("TA >= date '2024-01-01' and TA < date '2024-01-01'",
+ "TA >= date '2024-01-01' and TA < date '2024-01-01'");
+ assertRewrite("TA = date '2024-01-01' and TA > date '2024-01-10'",
"FALSE");
+ assertRewrite("TA > date '2024-01-05' or TA < date '2024-01-01'",
+ "TA > date '2024-01-05' or TA < date '2024-01-01'");
+ assertRewrite("TA > date '2024-01-05' or TA > date '2024-01-01' or TA
> date '2024-01-10'",
+ "TA > date '2024-01-01'");
+ assertRewrite("TA > date '2024-01-05' or TA > date '2024-01-01' or TA
< date '2024-01-10'", "TA IS NOT NULL");
+ assertRewriteNotNull("TA > date '2024-01-05' or TA > date '2024-01-01'
or TA < date '2024-01-10'", "TRUE");
+ assertRewrite("TA > date '2024-01-05' and TA > date '2024-01-01' and
TA > date '2024-01-10'",
+ "TA > date '2024-01-10'");
+ assertRewrite("TA > date '2024-01-05' and TA > date '2024-01-01' and
TA < date '2024-01-10'",
+ "TA > date '2024-01-05' and TA < date '2024-01-10'");
+ assertRewrite("TA > date '2024-01-05' or TA < date '2024-01-05'",
+ "TA > date '2024-01-05' or TA < date '2024-01-05'");
+ assertRewrite("TA > date '2024-01-01' or TA < date '2024-01-10'", "TA
IS NOT NULL");
+ assertRewriteNotNull("TA > date '2024-01-01' or TA < date
'2024-01-10'", "TRUE");
+ assertRewrite("TA > date '2024-01-05' and TA < date '2024-01-10'",
+ "TA > date '2024-01-05' and TA < date '2024-01-10'");
+ assertRewrite("TA > date '2024-01-05' and TA > date '2024-01-10'", "TA
> date '2024-01-10'");
+ assertRewrite("(TA > date '2024-01-01' and TA > date '2024-01-10') or
TA > date '2024-01-20'",
+ "TA > date '2024-01-10'");
+ assertRewrite("(TA > date '2024-01-01' or TA > date '2024-01-10') and
TA > date '2024-01-20'",
+ "TA > date '2024-01-20'");
+ assertRewrite("TA > date '2024-01-05' or TA > date '2024-01-05'", "TA
> date '2024-01-05'");
+ assertRewrite(
+ "(TA > date '2024-01-10' or TA > date '2024-01-20') and (TB >
date '2024-01-10' and TB < date '2024-01-20')",
+ "TA > date '2024-01-10' and (TB > date '2024-01-10' and TB <
date '2024-01-20') ");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03') and TA > date '2024-01-10'",
+ "FALSE");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03') and TA >= date '2024-01-01'",
+ "TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03')");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03') and TA > date '2024-01-01'",
+ "((TA = date '2024-01-02') OR (TA = date '2024-01-03'))");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03') or TA >= date '2024-01-01'",
+ "TA >= date '2024-01-01'");
+ assertRewrite("TA in (date '2024-01-01')", "TA in (date
'2024-01-01')");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03') and TA < date '2024-01-10'",
+ "TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03')");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03') and TA < date '2024-01-01'",
+ "FALSE");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03') or TA < date '2024-01-01'",
+ "TA in (date '2024-01-01',date '2024-01-02',date '2024-01-03')
or TA < date '2024-01-01'");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02') or TA in
(date '2024-01-02', date '2024-01-03')",
+ "TA in (date '2024-01-01',date '2024-01-02',date
'2024-01-03')");
+ assertRewrite("TA in (date '2024-01-01',date '2024-01-02') and TA in
(date '2024-01-03', date '2024-01-04')",
+ "FALSE");
+ assertRewrite("TA = date '2024-01-03' and TA = date '2024-01-01'",
"FALSE");
+ assertRewrite("TA in (date '2024-01-01') and TA in (date
'2024-01-03')", "FALSE");
+ assertRewrite("TA in (date '2024-01-03') and TA in (date
'2024-01-03')", "TA = date '2024-01-03'");
+ assertRewrite("(TA > date '2024-01-03' and TA < date '2024-01-01') and
TB < date '2024-01-05'", "FALSE");
+ assertRewrite("(TA > date '2024-01-03' and TA < date '2024-01-01') or
TB < date '2024-01-05'",
Review Comment:
add datetime test case
##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/SimplifyRangeTest.java:
##########
@@ -86,7 +86,8 @@ public void testSimplify() {
assertRewrite("(TA > 10 or TA > 20) and (TB > 10 and TB > 20)", "TA >
10 and TB > 20");
assertRewrite("((TB > 30 and TA > 40) and TA > 20) and (TB > 10 and TB
> 20)", "TB > 30 and TA > 40");
assertRewrite("(TA > 10 and TB > 10) or (TB > 10 and TB > 20)", "TA >
10 and TB > 10 or TB > 20");
- assertRewrite("((TA > 10 or TA > 5) and TB > 10) or (TB > 10 and (TB >
20 or TB < 10))", "(TA > 5 and TB > 10) or (TB > 10 and (TB > 20 or TB < 10))");
+ assertRewrite("((TA > 10 or TA > 5) and TB > 10) or (TB > 10 and (TB >
20 or TB < 10))",
+ "(TA > 5 and TB > 10) or (TB > 10 and (TB > 20 or TB < 10))");
Review Comment:
revert unnecessary format
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]