Skip to content

Commit

Permalink
Fix a bug in the downsampling code.
Browse files Browse the repository at this point in the history
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]

Bug reported by Matthieu Tourne.

Change-Id: I6d3875ccf83b67369e0db068503ed910d97ef0f6
  • Loading branch information
tsuna committed Dec 7, 2010
1 parent c8e5508 commit 87af5e7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/core/RowSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ public double doubleValue(final int i) {
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
Expand Down
5 changes: 4 additions & 1 deletion src/core/Span.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,10 @@ public long nextLongValue() {
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);
}
Expand Down

0 comments on commit 87af5e7

Please sign in to comment.