提交 3a460ebb authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix possible 30 seconds error for timestamp with time zone median

上级 cfe5ac5b
......@@ -243,15 +243,19 @@ class AggregateDataMedian extends AggregateData {
long dateSum = DateTimeUtils.absoluteDayFromDateValue(ts0.getDateValue())
+ DateTimeUtils.absoluteDayFromDateValue(ts1.getDateValue());
long nanos = (ts0.getTimeNanos() + ts1.getTimeNanos()) / 2;
int offset = ts0.getTimeZoneOffsetMins() + ts1.getTimeZoneOffsetMins();
if ((dateSum & 1) != 0) {
nanos += DateTimeUtils.NANOS_PER_DAY / 2;
if (nanos >= DateTimeUtils.NANOS_PER_DAY) {
nanos -= DateTimeUtils.NANOS_PER_DAY;
dateSum++;
}
}
if ((offset & 1) != 0) {
nanos += 30L * 1000000000;
}
if (nanos >= DateTimeUtils.NANOS_PER_DAY) {
nanos -= DateTimeUtils.NANOS_PER_DAY;
dateSum++;
}
return ValueTimestampTimeZone.fromDateValueAndNanos(DateTimeUtils.dateValueFromAbsoluteDay(dateSum / 2),
nanos, (short) ((ts0.getTimeZoneOffsetMins() + ts1.getTimeZoneOffsetMins()) / 2));
nanos, (short) (offset / 2));
}
default:
// Just return first
......
......@@ -633,13 +633,13 @@ select median(v) from test;
delete from test;
> update count: 5
insert into test values ('2000-01-20 20:00:00+10'), ('2000-01-21 20:00:00-09');
insert into test values ('2000-01-20 20:00:00+10:15'), ('2000-01-21 20:00:00-09');
> update count: 2
select median(v) from test;
> MEDIAN(V)
> ---------------------------
> 2000-01-21 08:00:00.0+00:30
> 2000-01-21 08:00:30.0+00:37
drop table test;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论