Search in sources :

Example 1 with LongTimeSeries

use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.

the class DeltaLongTimeSeriesSerialiser method deserialise.

@Override
public LongTimeSeries deserialise(final byte[] allBytes, final int offset, final int length) throws SerialisationException {
    if (allBytes.length == 0 || length == 0) {
        return null;
    }
    final ByteArrayInputStream bais = new ByteArrayInputStream(allBytes, offset, length);
    final DataInputStream dis = new DataInputStream(bais);
    final int bucketInt = (int) CompactRawSerialisationUtils.read(dis);
    final TimeBucket bucket = TimeBucket.values()[bucketInt];
    final int numEntries = (int) CompactRawSerialisationUtils.read(dis);
    final LongTimeSeries timeSeries = new LongTimeSeries(bucket);
    try {
        final boolean deltaMode = dis.readBoolean();
        if (deltaMode) {
            deltaDeserialise(timeSeries, numEntries, dis);
        } else {
            defaultDeserialise(timeSeries, numEntries, dis);
        }
    } catch (final IOException e) {
        throw new SerialisationException("IOException reading boolean", e);
    }
    return timeSeries;
}
Also used : SerialisationException(uk.gov.gchq.gaffer.exception.SerialisationException) ByteArrayInputStream(java.io.ByteArrayInputStream) LongTimeSeries(uk.gov.gchq.gaffer.time.LongTimeSeries) TimeBucket(uk.gov.gchq.gaffer.time.CommonTimeUtil.TimeBucket) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 2 with LongTimeSeries

use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.

the class DeltaLongTimeSeriesSerialiserTest method getExampleValueMillisecond.

private LongTimeSeries getExampleValueMillisecond() {
    final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.MILLISECOND);
    timeSeries.upsert(Instant.ofEpochMilli(1_000L), 1L);
    timeSeries.upsert(Instant.ofEpochMilli(3_000L), 10L);
    timeSeries.upsert(Instant.ofEpochMilli(1_000_000L), 10_000_000L);
    return timeSeries;
}
Also used : LongTimeSeries(uk.gov.gchq.gaffer.time.LongTimeSeries)

Example 3 with LongTimeSeries

use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.

the class DeltaLongTimeSeriesSerialiserTest method testSerialiserForEmptyTimeSeries.

@Test
public void testSerialiserForEmptyTimeSeries() throws SerialisationException {
    // Given
    final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.SECOND);
    // When
    final byte[] serialised = SERIALISER.serialise(timeSeries);
    final LongTimeSeries deserialised = SERIALISER.deserialise(serialised);
    // Then
    assertEquals(timeSeries, deserialised);
}
Also used : LongTimeSeries(uk.gov.gchq.gaffer.time.LongTimeSeries) Test(org.junit.jupiter.api.Test) ToBytesSerialisationTest(uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest)

Example 4 with LongTimeSeries

use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.

the class DeltaLongTimeSeriesSerialiserTest method getExampleValueSecond.

private LongTimeSeries getExampleValueSecond() {
    final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.SECOND);
    timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_SECOND * 100), 100L);
    timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_SECOND * 1_000), 100L);
    timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_SECOND * 1_000_000_000), 1_000_000_000L);
    return timeSeries;
}
Also used : LongTimeSeries(uk.gov.gchq.gaffer.time.LongTimeSeries)

Example 5 with LongTimeSeries

use of uk.gov.gchq.gaffer.time.LongTimeSeries in project Gaffer by gchq.

the class DeltaLongTimeSeriesSerialiserTest method getExampleValueMonth.

private LongTimeSeries getExampleValueMonth() {
    final LongTimeSeries timeSeries = new LongTimeSeries(TimeBucket.MONTH);
    timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_DAY * 30), 30L);
    timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_DAY * 90), 90L);
    timeSeries.upsert(Instant.ofEpochMilli(CommonTimeUtil.MILLISECONDS_IN_DAY * 1000), 1000L);
    return timeSeries;
}
Also used : LongTimeSeries(uk.gov.gchq.gaffer.time.LongTimeSeries)

Aggregations

LongTimeSeries (uk.gov.gchq.gaffer.time.LongTimeSeries)15 Test (org.junit.jupiter.api.Test)5 ToBytesSerialisationTest (uk.gov.gchq.gaffer.serialisation.ToBytesSerialisationTest)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 SerialisationException (uk.gov.gchq.gaffer.exception.SerialisationException)1 TimeBucket (uk.gov.gchq.gaffer.time.CommonTimeUtil.TimeBucket)1