diff --git a/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java b/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java index b11f7d1..b80a9aa 100644 --- a/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java +++ b/src/main/java/fi/iki/yak/ts/compression/gorilla/Compressor.java @@ -30,7 +30,7 @@ public Compressor(long timestamp, BitOutput output) { private void addHeader(long timestamp) { // One byte: length of the first delta // One byte: precision of timestamps - out.writeBits(timestamp, 64); +// out.writeBits(timestamp, 64); } /** @@ -43,7 +43,7 @@ public void addValue(long timestamp, long value) { if(storedTimestamp == 0) { writeFirst(timestamp, value); } else { - compressTimestamp(timestamp); +// compressTimestamp(timestamp); compressValue(value); } } @@ -58,7 +58,7 @@ public void addValue(long timestamp, double value) { if(storedTimestamp == 0) { writeFirst(timestamp, Double.doubleToRawLongBits(value)); } else { - compressTimestamp(timestamp); +// compressTimestamp(timestamp); compressValue(Double.doubleToRawLongBits(value)); } } @@ -68,7 +68,7 @@ private void writeFirst(long timestamp, long value) { storedTimestamp = timestamp; storedVal = value; - out.writeBits(storedDelta, FIRST_DELTA_BITS); +// out.writeBits(storedDelta, FIRST_DELTA_BITS); out.writeBits(storedVal, 64); } @@ -77,8 +77,9 @@ private void writeFirst(long timestamp, long value) { */ public void close() { // These are selected to test interoperability and correctness of the solution, this can be read with go-tsz - out.writeBits(0x0F, 4); - out.writeBits(0xFFFFFFFF, 32); + addValue(0, Double.NaN); +// out.writeBits(0x0F, 4); +// out.writeBits(0xFFFFFFFF, 32); out.skipBit(); out.flush(); } diff --git a/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor.java b/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor.java index adea8aa..1e56211 100644 --- a/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor.java +++ b/src/main/java/fi/iki/yak/ts/compression/gorilla/Decompressor.java @@ -19,9 +19,18 @@ public class Decompressor { private BitInput in; + private final static long NAN_LONG = 0x7ff8000000000000L; + + private final static int NAN_INT = 0x7fc00000; + + private final static double NAN_DOUBLE = Double.longBitsToDouble(0x7ff8000000000000L); + + private final static float NAN_FLOAT = Float.intBitsToFloat(0x7fc00000); + + public Decompressor(BitInput input) { in = input; - readHeader(); +// readHeader(); } private void readHeader() { @@ -44,15 +53,20 @@ public Pair readPair() { private void next() { if (storedTimestamp == 0) { // First item to read - storedDelta = in.getLong(Compressor.FIRST_DELTA_BITS); - if(storedDelta == (1<<27) - 1) { - endOfStream = true; - return; - } +// storedDelta = in.getLong(Compressor.FIRST_DELTA_BITS); +// if(storedDelta == (1<<27) - 1) { +// endOfStream = true; +// return; +// } storedVal = in.getLong(64); - storedTimestamp = blockTimestamp + storedDelta; + if (storedVal == NAN_LONG) { + endOfStream =true; + } +// storedTimestamp = blockTimestamp + storedDelta; + storedTimestamp = 1; } else { - nextTimestamp(); +// nextTimestamp(); + nextValue(); } } @@ -125,7 +139,13 @@ private void nextValue() { long value = in.getLong(64 - storedLeadingZeros - storedTrailingZeros); value <<= storedTrailingZeros; value = storedVal ^ value; - storedVal = value; + if (value == NAN_LONG) { + endOfStream = true; + return; + } else { + storedVal = value; + } + } } diff --git a/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java b/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java index 3c3f37a..62654ea 100644 --- a/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java +++ b/src/test/java/fi/iki/yak/ts/compression/gorilla/EncodeTest.java @@ -36,7 +36,7 @@ private void comparePairsToCompression(long blockTimestamp, Pair[] pairs) { // Replace with stream once decompressor supports it for(int i = 0; i < pairs.length; i++) { Pair pair = d.readPair(); - assertEquals(pairs[i].getTimestamp(), pair.getTimestamp(), "Timestamp did not match"); +// assertEquals(pairs[i].getTimestamp(), pair.getTimestamp(), "Timestamp did not match"); assertEquals(pairs[i].getDoubleValue(), pair.getDoubleValue(), "Value did not match"); } @@ -56,7 +56,7 @@ void simpleEncodeAndDecodeTest() throws Exception { new Pair(now + 400, Double.doubleToRawLongBits(2147483650.0)), new Pair(now + 2300, Double.doubleToRawLongBits(-16384)), new Pair(now + 16384, Double.doubleToRawLongBits(2.8)), - new Pair(now + 16500, Double.doubleToRawLongBits(-38.0)) + new Pair(now + 16500, Double.doubleToRawLongBits(-38.0)), }; comparePairsToCompression(now, pairs); @@ -368,7 +368,8 @@ void testEncodeSimilarFloats() throws Exception { // Replace with stream once decompressor supports it for(int i = 0; i < 5; i++) { Pair pair = d.readPair(); - assertEquals(bb.getLong(), pair.getTimestamp(), "Timestamp did not match"); +// assertEquals(bb.getLong(), pair.getTimestamp(), "Timestamp did not match"); + bb.getLong(); // read timestamp assertEquals(bb.getDouble(), pair.getDoubleValue(), "Value did not match"); } assertNull(d.readPair()); @@ -416,7 +417,7 @@ void testEncodeLargeAmountOfData() throws Exception { long tStamp = bb.getLong(); double val = bb.getDouble(); Pair pair = d.readPair(); - assertEquals(tStamp, pair.getTimestamp(), "Expected timestamp did not match at point " + i); +// assertEquals(tStamp, pair.getTimestamp(), "Expected timestamp did not match at point " + i); assertEquals(val, pair.getDoubleValue()); } assertNull(d.readPair()); @@ -482,7 +483,7 @@ void testLongEncoding() throws Exception { long tStamp = bb.getLong(); long val = bb.getLong(); Pair pair = d.readPair(); - assertEquals(tStamp, pair.getTimestamp(), "Expected timestamp did not match at point " + i); +// assertEquals(tStamp, pair.getTimestamp(), "Expected timestamp did not match at point " + i); assertEquals(val, pair.getLongValue()); } assertNull(d.readPair());