Search in sources :

Example 11 with Interval

use of com.questdb.std.time.Interval in project questdb by bluestreak01.

the class QueryTest method testIterateOverInterval.

@Test
public void testIterateOverInterval() {
    int count = 0;
    long timestamp = 0;
    for (Quote a : q.all().bufferedIterator(new Interval(ts2, ts1))) {
        count++;
        Assert.assertTrue(timestamp <= a.getTimestamp());
        timestamp = a.getTimestamp();
    }
    Assert.assertEquals(92, count);
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 12 with Interval

use of com.questdb.std.time.Interval in project questdb by bluestreak01.

the class QueryTest method testAllBySymbolValuesOverInterval.

@Test
public void testAllBySymbolValuesOverInterval() throws Exception {
    ResultSet<Quote> rs = q.all().withKeys().slice(new Interval(ts2, ts1)).asResultSet();
    Assert.assertEquals(0, rs.size());
    String expected = "2013-04-29T01:40:00.000Z\tWTB.L\t0.154905273744959\t0.3463641298845208\t1190004376\t548681062\tFast trading\tSK\n" + "2013-04-29T07:13:20.000Z\tWTB.L\t0.94782183700974\t0.6385933398879912\t507408673\t477022979\tFast trading\tSK\n" + "2013-04-29T12:46:40.000Z\tBT-A.L\t0.3542490655977256\t0.19109723285077962\t1111156559\t746276626\tFast trading\tSK\n" + "2013-04-30T04:03:20.000Z\tWTB.L\t0.47797848524672126\t0.6430092838094059\t1405625919\t753070187\tFast trading\tLXE\n" + "2013-04-30T11:00:00.000Z\tBT-A.L\t0.7630002744048395\t0.5655301296325983\t170034893\t555018287\tFast trading\tGR\n" + "2013-04-30T22:06:40.000Z\tBT-A.L\t0.7147870329232192\t0.5047251666299352\t1632653036\t1459199712\tFast trading\tGR\n" + "2013-05-01T10:36:40.000Z\tBT-A.L\t0.6561113751342125\t0.47910748281262994\t514913551\t831670347\tFast trading\tLXE\n" + "2013-05-01T14:46:40.000Z\tWTB.L\t0.9460194923216076\t0.09048831254437362\t1231092052\t1026180063\tFast trading\tLXE\n" + "2013-05-02T07:26:40.000Z\tBT-A.L\t0.9029266635624776\t0.4400626920975901\t188866311\t1663084154\tFast trading\tSK\n" + "2013-05-02T13:00:00.000Z\tBT-A.L\t0.4129219991106413\t0.5025269563465262\t944280080\t148476167\tFast trading\tLXE\n" + "2013-05-02T14:23:20.000Z\tWTB.L\t0.7858327043313086\t0.7679013186397453\t150870909\t427886371\tFast trading\tGR\n" + "2013-05-02T18:33:20.000Z\tBT-A.L\t0.9296374772157955\t0.19088899950218174\t980203892\t1476326981\tFast trading\tLXE\n" + "2013-05-02T22:43:20.000Z\tBT-A.L\t0.12282110119740142\t0.822933043281861\t997442403\t430556502\tFast trading\tSK\n" + "2013-05-03T01:30:00.000Z\tWTB.L\t0.6696457609278927\t0.7177695674107006\t1859909396\t1567568718\tFast trading\tSK\n" + "2013-05-03T07:03:20.000Z\tBT-A.L\t0.008144226019699663\t0.8149620429664706\t1492076657\t2143247261\tFast trading\tLXE\n";
    rs = q.all().withKeys("WTB.L", "BT-A.L").slice(new Interval(ts2, ts1)).asResultSet();
    TestUtils.assertEquals(expected, rs.sort());
}
Also used : Quote(com.questdb.model.Quote) Interval(com.questdb.std.time.Interval) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 13 with Interval

use of com.questdb.std.time.Interval in project questdb by bluestreak01.

the class Journal method configurePartitions.

private void configurePartitions() {
    File[] files = getLocation().listFiles(f -> f.isDirectory() && !f.getName().startsWith(Constants.TEMP_DIRECTORY_PREFIX));
    int partitionIndex = 0;
    if (files != null && tx.journalMaxRowID > 0) {
        Arrays.sort(files);
        for (int i = 0; i < files.length; i++) {
            File f = files[i];
            if (partitionIndex > Rows.toPartitionIndex(tx.journalMaxRowID)) {
                break;
            }
            long txLimit = Journal.TX_LIMIT_EVAL;
            long[] indexTxAddresses = null;
            if (partitionIndex == Rows.toPartitionIndex(tx.journalMaxRowID)) {
                txLimit = Rows.toLocalRowID(tx.journalMaxRowID);
                indexTxAddresses = tx.indexPointers;
            }
            try {
                Interval interval = new Interval(f.getName(), getMetadata().getPartitionBy());
                if (partitionIndex < partitions.size()) {
                    Partition<T> partition = partitions.getQuick(partitionIndex);
                    Interval that = partition.getInterval();
                    if (that == null || that.equals(interval)) {
                        partition.applyTx(txLimit, indexTxAddresses);
                        partitionIndex++;
                    } else {
                        partition.close();
                        partitions.remove(partitionIndex);
                    }
                } else {
                    partitions.add(new Partition<>(this, interval, partitionIndex++, txLimit, indexTxAddresses, sequentialAccess));
                }
            } catch (NumericException e) {
                LOG.info().$("Foreign directory: ").$(f.getName()).$();
            }
        }
    }
    configureIrregularPartition();
}
Also used : NumericException(com.questdb.common.NumericException) File(java.io.File) Interval(com.questdb.std.time.Interval)

Example 14 with Interval

use of com.questdb.std.time.Interval in project questdb by bluestreak01.

the class Journal method createTempPartition.

public TempPartition<T> createTempPartition(String name) {
    int lag = getMetadata().getLag();
    if (lag < 1) {
        throw new JournalRuntimeException("Journal doesn't support temp partitions: %s", this);
    }
    Interval interval = null;
    if (getMetadata().getPartitionBy() != PartitionBy.NONE) {
        Partition<T> p = partitions.getLast();
        if (p != null) {
            Interval lastPartitionInterval = p.getInterval();
            interval = new Interval(lastPartitionInterval.getLo(), Dates.addHours(lastPartitionInterval.getHi(), lag));
        } else {
            interval = new Interval(System.currentTimeMillis(), getMetadata().getPartitionBy());
        }
    }
    return new TempPartition<>(this, interval, nonLagPartitionCount(), name);
}
Also used : JournalRuntimeException(com.questdb.common.JournalRuntimeException) Interval(com.questdb.std.time.Interval)

Example 15 with Interval

use of com.questdb.std.time.Interval in project questdb by bluestreak01.

the class JournalDeltaConsumer method createPartitions.

private void createPartitions(JournalServerState metadata) throws JournalException {
    int pc = journal.nonLagPartitionCount() - 1;
    for (int i = 0, k = metadata.getNonLagPartitionCount(); i < k; i++) {
        JournalServerState.PartitionMetadata partitionMetadata = metadata.getMeta(i);
        if (partitionMetadata.getPartitionIndex() > pc) {
            Interval interval = new Interval(partitionMetadata.getIntervalEnd(), partitionMetadata.getIntervalStart());
            journal.createPartition(interval, partitionMetadata.getPartitionIndex());
        }
    }
}
Also used : JournalServerState(com.questdb.net.ha.model.JournalServerState) 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