Search in sources :

Example 6 with Interval

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);
    }
}
Also used : Interval(com.questdb.std.time.Interval)

Example 7 with Interval

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());
    }
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 8 with Interval

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);
        }
    }
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 9 with Interval

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);
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 10 with Interval

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;
}
Also used : Interval(com.questdb.std.time.Interval)

Aggregations

Interval (com.questdb.std.time.Interval)15 Quote (com.questdb.model.Quote)8 AbstractTest (com.questdb.test.tools.AbstractTest)8 Test (org.junit.Test)8 JournalRuntimeException (com.questdb.common.JournalRuntimeException)1 NumericException (com.questdb.common.NumericException)1 IncompatibleJournalException (com.questdb.ex.IncompatibleJournalException)1 JournalServerState (com.questdb.net.ha.model.JournalServerState)1 JournalException (com.questdb.std.ex.JournalException)1 File (java.io.File)1