From cd083c082a9c11e231a04a3a727771096b031a92 Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Mon, 6 Dec 2010 23:18:06 -0800 Subject: [PATCH] Fix a bug in the downsampling code. Any attempt to downsample a mix of integer values and floating values would result in an Internal Server Error caused by: java.lang.ClassCastException: value #N is not a float in RowSeq(...) at net.opentsdb.core.RowSeq.doubleValue(RowSeq.java:288) at net.opentsdb.core.Span$DownsamplingIterator.nextDoubleValue(Span.java:508) at net.opentsdb.core.Aggregators$Avg.runDouble(Aggregators.java:169) at net.opentsdb.core.Span$DownsamplingIterator.next(Span.java:418) at net.opentsdb.core.SpanGroup$SGIterator.moveToNext(SpanGroup.java:604) [... in tsdb-1.0.jar as of 08a85bb] Change-Id: I6d3875ccf83b67369e0db068503ed910d97ef0f6 --- src/core/RowSeq.java | 11 +++++++++++ src/core/Span.java | 5 ++++- 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/src/core/RowSeq.java b/src/core/RowSeq.java index 7659e12..c24cec9 100644 --- a/src/core/RowSeq.java +++ b/src/core/RowSeq.java @@ -288,6 +288,17 @@ final class RowSeq implements DataPoints { throw new ClassCastException("value #" + i + " is not a float in " + this); } + /** + * Returns the {@code i}th data point as a double value. + */ + double toDouble(final int i) { + if (isInteger(i)) { + return values[i]; + } else { + return Float.intBitsToFloat((int) values[i]); + } + } + /** Returns a human readable string representation of the object. */ public String toString() { // The argument passed to StringBuilder is a pretty good estimate of the diff --git a/src/core/Span.java b/src/core/Span.java index 248e941..bc05339 100644 --- a/src/core/Span.java +++ b/src/core/Span.java @@ -505,7 +505,10 @@ final class Span implements DataPoints { public double nextDoubleValue() { if (hasNextValue()) { moveToNext(); - return current_row.doubleValue(pos); + // Use `toDouble' instead of `doubleValue' because we can get here if + // there's a mix of integer values and floating point values in the + // current downsampled interval. + return current_row.toDouble(pos); } throw new NoSuchElementException("no more floats in interval of " + this); } -- 1.7.3.1.121.g64a71