use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class PartitionTest method getPartitionForTimestamp.
private <T> Partition<T> getPartitionForTimestamp(Journal<T> journal, long timestamp) throws JournalException {
int sz = journal.getPartitionCount();
for (int i = 0; i < sz; i++) {
Partition<T> result = journal.getPartition(i, false);
Interval interval = result.getInterval();
if (interval == null || interval.contains(timestamp)) {
return result;
}
}
if (journal.getPartition(0, false).getInterval().isAfter(timestamp)) {
return journal.getPartition(0, false);
} else {
return journal.getPartition(sz - 1, false);
}
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class QueryTest method testLatestByKeyWithinMonths.
@Test
public void testLatestByKeyWithinMonths() throws Exception {
long max = w.getAppendTimestampLo();
long inc = System.currentTimeMillis() - max;
try (JournalWriter<Quote> w2 = getFactory().writer(Quote.class, "w2")) {
for (Quote a : JournalIterators.bufferedIterator(q.getJournal())) {
a.setTimestamp(a.getTimestamp() + inc);
w2.append(a);
}
Query<Quote> q = w2.query();
long millis;
Interval interval = new Interval(Dates.addMonths(millis = System.currentTimeMillis(), -1), millis);
UnorderedResultSet<Quote> rs = q.getJournal().query().head().withKeys().limit(interval).asResultSet();
Assert.assertEquals(10, rs.size());
}
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class QueryTest method testParallelIteratorInterval.
@Test
public void testParallelIteratorInterval() throws Exception {
Interval interval = new Interval("2013-05-04T06:40:00.000Z", "2013-05-05T17:23:20.000Z");
try (Journal<Quote> r = getFactory().reader(Quote.class)) {
Query<Quote> q2 = r.query();
JournalIterator<Quote> expected = q.all().iterator(interval);
try (ConcurrentIterator<Quote> actual = q2.all().concurrentIterator(interval)) {
TestUtils.assertEquals(expected, actual);
}
}
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class QueryTest method testLatestByKeyValueOverInterval.
@Test
public void testLatestByKeyValueOverInterval() throws JournalException {
Quote Quote = q.head().withKeys("RRS.L").limit(new Interval(ts2, ts1)).asResultSet().readFirst();
Assert.assertNotNull(Quote);
Assert.assertEquals(0.5590262812936236, Quote.getBid(), 0.00000000001);
}
use of com.questdb.std.time.Interval in project questdb by bluestreak01.
the class AbstractResultSetBuilder method next.
public boolean next(Partition<T> partition, boolean desc) throws JournalException {
Interval that = partition.getInterval();
if (interval != null && that != null && (that.getLo() > interval.getHi() || that.getHi() < interval.getLo())) {
return (that.getHi() < interval.getLo() && !desc) || (that.getLo() > interval.getHi() && desc);
}
switch(accept(partition)) {
case SKIP:
return false;
case BREAK:
return true;
default:
break;
}
long size = partition.open().size();
if (size > 0) {
long lo = 0;
long hi = size - 1;
if (interval != null && partition.getInterval() != null) {
if (partition.getInterval().getLo() < interval.getLo()) {
long _lo = partition.indexOf(interval.getLo(), BSearchType.NEWER_OR_SAME);
// there are no data with timestamp later then start date of interval, skip partition
if (_lo == -2) {
return false;
}
lo = _lo;
}
if (partition.getInterval().getHi() > interval.getHi()) {
long _hi = partition.indexOf(interval.getHi(), BSearchType.OLDER_OR_SAME);
// there are no data with timestamp earlier then end date of interval, skip partition
if (_hi == -1) {
return false;
}
hi = _hi;
}
}
if (lo <= hi) {
read(lo, hi);
}
}
return false;
}
Aggregations