Skip to content

Commit 4f9b79f

Browse files
committed
fix failed case
1 parent de68adc commit 4f9b79f

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/executable/DateTimeExtractAndTransform.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,10 @@ public static Expression fromUnixTime(DecimalLiteral second, StringLikeLiteral f
581581
throw new AnalysisException("Operation from_unixtime of " + second.getValue() + " out of range");
582582
}
583583

584+
BigDecimal decimalVal = second.getValue();
585+
BigDecimal microSeconds = decimalVal.movePointRight(decimalVal.scale()).setScale(0, RoundingMode.DOWN);
584586
ZonedDateTime dateTime = LocalDateTime.of(1970, 1, 1, 0, 0, 0)
585-
.plusSeconds(second.getValue().longValue())
587+
.plus(microSeconds.longValue(), ChronoUnit.MICROS)
586588
.atZone(ZoneId.of("UTC+0"))
587589
.toOffsetDateTime()
588590
.atZoneSameInstant(DateUtils.getTimeZone());
@@ -606,9 +608,10 @@ public static Expression fromUnixTime(DecimalV3Literal second, StringLikeLiteral
606608
if (second.getValue().signum() < 0) {
607609
throw new AnalysisException("Operation from_unixtime of " + second.getValue() + " out of range");
608610
}
609-
611+
BigDecimal decimalVal = second.getValue();
612+
BigDecimal microSeconds = decimalVal.movePointRight(decimalVal.scale()).setScale(0, RoundingMode.DOWN);
610613
ZonedDateTime dateTime = LocalDateTime.of(1970, 1, 1, 0, 0, 0)
611-
.plusSeconds(second.getValue().longValue())
614+
.plus(microSeconds.longValue(), ChronoUnit.MICROS)
612615
.atZone(ZoneId.of("UTC+0"))
613616
.toOffsetDateTime()
614617
.atZoneSameInstant(DateUtils.getTimeZone());

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,13 @@ void testFoldString() {
474474
rewritten = executor.rewrite(f, context);
475475
Assertions.assertEquals(new VarcharLiteral("73 11 30"), rewritten);
476476

477-
f = new FromUnixtime(DecimalLiteral.of(new BigDecimal("1761548288.000000")));
477+
f = new FromUnixtime(DecimalLiteral.of(new BigDecimal("1761548288.100000")));
478478
rewritten = executor.rewrite(f, context);
479-
Assertions.assertEquals(new VarcharLiteral("2025-10-27 14:58:08.000000"), rewritten);
479+
Assertions.assertEquals(new VarcharLiteral("2025-10-27 14:58:08.100000"), rewritten);
480480

481-
f = new FromUnixtime(DecimalV3Literal.of(new BigDecimal("1761548288.000000")));
481+
f = new FromUnixtime(DecimalV3Literal.of(new BigDecimal("1761548288.100000")));
482482
rewritten = executor.rewrite(f, context);
483-
Assertions.assertEquals(new VarcharLiteral("2025-10-27 14:58:08.000000"), rewritten);
483+
Assertions.assertEquals(new VarcharLiteral("2025-10-27 14:58:08.100000"), rewritten);
484484

485485
UnixTimestamp ut = new UnixTimestamp(StringLiteral.of("2021-11-11"), StringLiteral.of("%Y-%m-%d"));
486486
rewritten = executor.rewrite(ut, context);

regression-test/suites/nereids_rules_p0/partition_prune/one_key_range_part_test.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ suite("one_key_range_part_test") {
103103
}
104104
explain {
105105
sql("SELECT a, dt, c FROM key_1_fixed_range_date_part WHERE dt = from_unixtime(unix_timestamp('2023-05-20 12:00:00'));")
106-
contains "14/14 (p_min,p_202301,p_202302,p_202303,p_202304,p_202305,p_202306,p_202307,p_202308,p_202309,p_202310,p_202311,p_202312,p_max)"
106+
contains "1/14 (p_202305)"
107107
}
108108
explain {
109109
sql("SELECT a, dt, c FROM key_1_fixed_range_date_part WHERE date(dt) = '2023-09-05';")
@@ -234,7 +234,7 @@ suite("one_key_range_part_test") {
234234
}
235235
explain {
236236
sql("SELECT a, dt, c FROM key_1_special_fixed_range_date_part WHERE dt = from_unixtime(unix_timestamp('2023-11-20 12:00:00'));")
237-
contains "10/10 (p_min,p_202301,p_202302,p_202304,p_202305,p_202306,p_202309,p_202310,p_202312,p_max)"
237+
contains "1/10 (p_202310)"
238238
}
239239
explain {
240240
sql("SELECT a, dt, c FROM key_1_special_fixed_range_date_part WHERE date(dt) = '2023-09-05';")

regression-test/suites/nereids_rules_p0/partition_prune/one_key_range_part_update_test.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ suite("one_key_range_part_update_test") {
9696
}
9797
explain {
9898
sql("SELECT a, dt, c FROM key_1_special_fixed_range_date_part_update WHERE dt = from_unixtime(unix_timestamp('2023-08-20 12:00:00'));")
99-
contains "11/11 (p_min,p_202301,p_202302,p_202304,p_202305,p_202306,p_202308,p_202309,p_202310,p_202312,p_max)"
99+
contains "1/11 (p_202308)"
100100
}
101101
explain {
102102
sql("SELECT a, dt, c FROM key_1_special_fixed_range_date_part_update WHERE date(dt) = '2023-08-05';")

0 commit comments

Comments
 (0)