Search in sources :

Example 1 with DateRangeBound

use of com.datastax.dse.driver.api.core.data.time.DateRangeBound in project nosqlbench by nosqlbench.

the class DateRangeDuring method apply.

@Override
public DateRange apply(long value) {
    ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), zoneid);
    DateRangeBound lower = DateRangeBound.lowerBound(date, precision);
    DateRangeBound upper = DateRangeBound.upperBound(date, precision);
    DateRange dateRange = new DateRange(lower, upper);
    return dateRange;
}
Also used : DateRangeBound(com.datastax.dse.driver.api.core.data.time.DateRangeBound) DateRange(com.datastax.dse.driver.api.core.data.time.DateRange) ZonedDateTime(java.time.ZonedDateTime)

Example 2 with DateRangeBound

use of com.datastax.dse.driver.api.core.data.time.DateRangeBound in project nosqlbench by nosqlbench.

the class DateRangeFunc method apply.

@Override
public DateRange apply(long value) {
    ZonedDateTime lowerDate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(lower.applyAsLong(value)), zoneid);
    DateRangeBound lower = DateRangeBound.lowerBound(lowerDate, precision);
    ZonedDateTime upperDate = ZonedDateTime.ofInstant(Instant.ofEpochMilli(upper.applyAsLong(value)), zoneid);
    DateRangeBound upper = DateRangeBound.upperBound(upperDate, precision);
    DateRange dateRange = new DateRange(lower, upper);
    return dateRange;
}
Also used : DateRangeBound(com.datastax.dse.driver.api.core.data.time.DateRangeBound) DateRange(com.datastax.dse.driver.api.core.data.time.DateRange) ZonedDateTime(java.time.ZonedDateTime)

Example 3 with DateRangeBound

use of com.datastax.dse.driver.api.core.data.time.DateRangeBound in project nosqlbench by nosqlbench.

the class DateRangeOnOrBefore method apply.

@Override
public DateRange apply(long value) {
    ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), zoneid);
    DateRangeBound lower = DateRangeBound.UNBOUNDED;
    DateRangeBound upper = DateRangeBound.upperBound(date, precision);
    DateRange dateRange = new DateRange(lower, upper);
    return dateRange;
}
Also used : DateRangeBound(com.datastax.dse.driver.api.core.data.time.DateRangeBound) DateRange(com.datastax.dse.driver.api.core.data.time.DateRange) ZonedDateTime(java.time.ZonedDateTime)

Example 4 with DateRangeBound

use of com.datastax.dse.driver.api.core.data.time.DateRangeBound in project java-driver by datastax.

the class DateRangeCodec method encode.

@Nullable
@Override
public ByteBuffer encode(@Nullable DateRange dateRange, @NonNull ProtocolVersion protocolVersion) {
    if (dateRange == null) {
        return null;
    }
    byte rangeType = encodeType(dateRange);
    int bufferSize = 1;
    DateRangeBound lowerBound = dateRange.getLowerBound();
    Optional<DateRangeBound> maybeUpperBound = dateRange.getUpperBound();
    bufferSize += lowerBound.isUnbounded() ? 0 : 9;
    bufferSize += maybeUpperBound.map(upperBound -> upperBound.isUnbounded() ? 0 : 9).orElse(0);
    ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
    buffer.put(rangeType);
    if (!lowerBound.isUnbounded()) {
        put(buffer, lowerBound);
    }
    maybeUpperBound.ifPresent(upperBound -> {
        if (!upperBound.isUnbounded()) {
            put(buffer, upperBound);
        }
    });
    return (ByteBuffer) buffer.flip();
}
Also used : DateRangeBound(com.datastax.dse.driver.api.core.data.time.DateRangeBound) ByteBuffer(java.nio.ByteBuffer) Nullable(edu.umd.cs.findbugs.annotations.Nullable)

Example 5 with DateRangeBound

use of com.datastax.dse.driver.api.core.data.time.DateRangeBound in project nosqlbench by nosqlbench.

the class DateRangeOnOrAfter method apply.

@Override
public DateRange apply(long value) {
    ZonedDateTime date = ZonedDateTime.ofInstant(Instant.ofEpochMilli(value), zoneid);
    DateRangeBound lower = DateRangeBound.lowerBound(date, precision);
    DateRangeBound upper = DateRangeBound.UNBOUNDED;
    DateRange dateRange = new DateRange(lower, upper);
    return dateRange;
}
Also used : DateRangeBound(com.datastax.dse.driver.api.core.data.time.DateRangeBound) DateRange(com.datastax.dse.driver.api.core.data.time.DateRange) ZonedDateTime(java.time.ZonedDateTime)

Aggregations

DateRangeBound (com.datastax.dse.driver.api.core.data.time.DateRangeBound)5 DateRange (com.datastax.dse.driver.api.core.data.time.DateRange)4 ZonedDateTime (java.time.ZonedDateTime)4 Nullable (edu.umd.cs.findbugs.annotations.Nullable)1 ByteBuffer (java.nio.ByteBuffer)1