Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a90d30

Browse filesBrowse files
yujun777Your Name
authored and
Your Name
committed
[fix](nereids) fix comparison with date like (#45735)
### What problem does this PR solve? Issue Number: close #xxx Related PR: #45382 Problem Summary: #45382 had fix compare date/datev1 with datetime literal wrong cutting. but it not fix completely. ``` if (right instanceof DateTimeLiteral) { DateTimeLiteral dateTimeLiteral = (DateTimeLiteral) right; right = migrateToDateV2(dateTimeLiteral); if (dateTimeLiteral.getHour() != 0 || dateTimeLiteral.getMinute() != 0 || dateTimeLiteral.getSecond() != 0) { ... } } ``` For the above code, if check right is date time literal, but notice that datetimev2 literal is datetime literal's child class. so datetimev2 literal will also run the above code. And datetimev2 literal should check its microseconds not equals to 0. for example: `date_a = '2020-01-01 00:00:00.01'` should opt as `FALSE`, but not `date_a = '2020-01-01'`.
1 parent fe3632a commit 3a90d30
Copy full SHA for 3a90d30

File tree

2 files changed

+25
-1
lines changed
Filter options

2 files changed

+25
-1
lines changed

‎fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java

Copy file name to clipboardExpand all lines: fe/fe-core/src/main/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicate.java
+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ private static Expression processDateLikeTypeCoercion(ComparisonPredicate cp, Ex
176176
DateTimeLiteral dateTimeLiteral = (DateTimeLiteral) right;
177177
right = migrateToDateV2(dateTimeLiteral);
178178
if (dateTimeLiteral.getHour() != 0 || dateTimeLiteral.getMinute() != 0
179-
|| dateTimeLiteral.getSecond() != 0) {
179+
|| dateTimeLiteral.getSecond() != 0 || dateTimeLiteral.getMicroSecond() != 0) {
180180
if (cp instanceof EqualTo) {
181181
return ExpressionUtils.falseOrNull(cast.child());
182182
} else if (cp instanceof NullSafeEqual) {

‎fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicateTest.java

Copy file name to clipboardExpand all lines: fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/rules/SimplifyComparisonPredicateTest.java
+24
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ void testDateTimeV2CmpDateTimeV2() {
153153
new LessThan(date, new DateV2Literal("2020-01-02")));
154154
assertRewrite(new LessThanEqual(new Cast(date, DateTimeType.INSTANCE), new DateTimeLiteral("2020-01-01 00:00:01")),
155155
new LessThanEqual(date, new DateV2Literal("2020-01-01")));
156+
assertRewrite(new EqualTo(new Cast(date, DateTimeV2Type.SYSTEM_DEFAULT), new DateTimeV2Literal("2020-01-01 00:00:00")),
157+
new EqualTo(date, new DateV2Literal("2020-01-01")));
158+
assertRewrite(new EqualTo(new Cast(date, DateTimeV2Type.SYSTEM_DEFAULT), new DateTimeV2Literal("2020-01-01 00:00:01")),
159+
ExpressionUtils.falseOrNull(date));
160+
assertRewrite(new EqualTo(new Cast(date, DateTimeV2Type.of(2)), new DateTimeV2Literal("2020-01-01 00:00:00.01")),
161+
ExpressionUtils.falseOrNull(date));
162+
assertRewrite(new NullSafeEqual(new Cast(date, DateTimeV2Type.of(2)), new DateTimeV2Literal("2020-01-01 00:00:00.01")),
163+
BooleanLiteral.FALSE);
164+
assertRewrite(new GreaterThanEqual(new Cast(date, DateTimeV2Type.SYSTEM_DEFAULT), new DateTimeV2Literal("2020-01-01 00:00:01")),
165+
new GreaterThanEqual(date, new DateV2Literal("2020-01-02")));
166+
assertRewrite(new GreaterThanEqual(new Cast(date, DateTimeV2Type.of(2)), new DateTimeV2Literal("2020-01-01 00:00:00.01")),
167+
new GreaterThanEqual(date, new DateV2Literal("2020-01-02")));
156168
// cast (date as datev1) = datev1-literal
157169
// assertRewrite(new EqualTo(new Cast(date, DateType.INSTANCE), new DateLiteral("2020-01-01")),
158170
// new EqualTo(date, new DateV2Literal("2020-01-01")));
@@ -178,6 +190,18 @@ void testDateTimeV2CmpDateTimeV2() {
178190
new EqualTo(datev1, new DateLiteral("2020-01-01")));
179191
assertRewrite(new GreaterThan(new Cast(datev1, DateV2Type.INSTANCE), new DateV2Literal("2020-01-01")),
180192
new GreaterThan(datev1, new DateLiteral("2020-01-01")));
193+
assertRewrite(new EqualTo(new Cast(datev1, DateTimeV2Type.SYSTEM_DEFAULT), new DateTimeV2Literal("2020-01-01 00:00:00")),
194+
new EqualTo(datev1, new DateLiteral("2020-01-01")));
195+
assertRewrite(new EqualTo(new Cast(datev1, DateTimeV2Type.SYSTEM_DEFAULT), new DateTimeV2Literal("2020-01-01 00:00:01")),
196+
ExpressionUtils.falseOrNull(datev1));
197+
assertRewrite(new EqualTo(new Cast(datev1, DateTimeV2Type.of(2)), new DateTimeV2Literal("2020-01-01 00:00:00.01")),
198+
ExpressionUtils.falseOrNull(datev1));
199+
assertRewrite(new NullSafeEqual(new Cast(datev1, DateTimeV2Type.of(2)), new DateTimeV2Literal("2020-01-01 00:00:00.01")),
200+
BooleanLiteral.FALSE);
201+
assertRewrite(new GreaterThanEqual(new Cast(datev1, DateTimeV2Type.SYSTEM_DEFAULT), new DateTimeV2Literal("2020-01-01 00:00:01")),
202+
new GreaterThanEqual(datev1, new DateLiteral("2020-01-02")));
203+
assertRewrite(new GreaterThanEqual(new Cast(datev1, DateTimeV2Type.of(2)), new DateTimeV2Literal("2020-01-01 00:00:00.01")),
204+
new GreaterThanEqual(datev1, new DateLiteral("2020-01-02")));
181205

182206
// cast (datetimev1 as datetime) cmp datetime
183207
assertRewrite(new EqualTo(new Cast(datetimev1, DateTimeV2Type.of(0)), new DateTimeV2Literal("2020-01-01 00:00:00")),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.