提交 4776fd48 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Overflow of nanoseconds is not possible in AddgegateDataMedian.getMedian()

上级 8b1dc0fd
...@@ -73,7 +73,7 @@ class AggregateDataMedian extends AggregateData { ...@@ -73,7 +73,7 @@ class AggregateDataMedian extends AggregateData {
static Value getMedian(Value v0, Value v1, int dataType, CompareMode mode) { static Value getMedian(Value v0, Value v1, int dataType, CompareMode mode) {
if (v0.compareTo(v1, mode) == 0) { if (v0.compareTo(v1, mode) == 0) {
return v1.convertTo(dataType); return v0.convertTo(dataType);
} }
switch (dataType) { switch (dataType) {
case Value.BYTE: case Value.BYTE:
...@@ -100,19 +100,18 @@ class AggregateDataMedian extends AggregateData { ...@@ -100,19 +100,18 @@ class AggregateDataMedian extends AggregateData {
case Value.TIMESTAMP: { case Value.TIMESTAMP: {
ValueTimestamp ts0 = (ValueTimestamp) v0.convertTo(Value.TIMESTAMP), ValueTimestamp ts0 = (ValueTimestamp) v0.convertTo(Value.TIMESTAMP),
ts1 = (ValueTimestamp) v1.convertTo(Value.TIMESTAMP); ts1 = (ValueTimestamp) v1.convertTo(Value.TIMESTAMP);
return DateTimeUtils.normalizeTimestamp( return ValueTimestamp.fromDateValueAndNanos(
(DateTimeUtils.absoluteDayFromDateValue(ts0.getDateValue()) DateTimeUtils.dateValueFromAbsoluteDay((DateTimeUtils.absoluteDayFromDateValue(ts0.getDateValue())
+ DateTimeUtils.absoluteDayFromDateValue(ts1.getDateValue())) / 2, + DateTimeUtils.absoluteDayFromDateValue(ts1.getDateValue())) / 2),
(ts0.getTimeNanos() + ts1.getTimeNanos()) / 2); (ts0.getTimeNanos() + ts1.getTimeNanos()) / 2);
} }
case Value.TIMESTAMP_TZ: { case Value.TIMESTAMP_TZ: {
ValueTimestampTimeZone ts0 = (ValueTimestampTimeZone) v0.convertTo(Value.TIMESTAMP_TZ), ValueTimestampTimeZone ts0 = (ValueTimestampTimeZone) v0.convertTo(Value.TIMESTAMP_TZ),
ts1 = (ValueTimestampTimeZone) v1.convertTo(Value.TIMESTAMP_TZ); ts1 = (ValueTimestampTimeZone) v1.convertTo(Value.TIMESTAMP_TZ);
ValueTimestamp ts = DateTimeUtils.normalizeTimestamp( return ValueTimestampTimeZone.fromDateValueAndNanos(
(DateTimeUtils.absoluteDayFromDateValue(ts0.getDateValue()) DateTimeUtils.dateValueFromAbsoluteDay((DateTimeUtils.absoluteDayFromDateValue(ts0.getDateValue())
+ DateTimeUtils.absoluteDayFromDateValue(ts1.getDateValue())) / 2, + DateTimeUtils.absoluteDayFromDateValue(ts1.getDateValue())) / 2),
(ts0.getTimeNanos() + ts1.getTimeNanos()) / 2); (ts0.getTimeNanos() + ts1.getTimeNanos()) / 2,
return ValueTimestampTimeZone.fromDateValueAndNanos(ts.getDateValue(), ts.getTimeNanos(),
(short) ((ts0.getTimeZoneOffsetMins() + ts1.getTimeZoneOffsetMins()) / 2)); (short) ((ts0.getTimeZoneOffsetMins() + ts1.getTimeZoneOffsetMins()) / 2));
} }
default: default:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论