Search in sources :

Example 66 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class Generator method createCustomers.

public static void createCustomers(WriterFactory factory) throws JournalException {
    // to populate it.
    try (JournalWriter writer = factory.writer(new JournalStructure("customers").$int("id").$str("name").$ts("updateDate").$())) {
        Rnd rnd = new Rnd();
        int updateDateIndex = writer.getMetadata().getColumnIndex("updateDate");
        long timestamp = System.currentTimeMillis();
        for (int i = 0; i < 1000000; i++) {
            // timestamp order is enforced by passing value to entryWriter() call
            // in this example we don't pass timestamp and ordering is not enforced
            JournalEntryWriter ew = writer.entryWriter();
            // columns accessed by index
            ew.putInt(0, rnd.nextPositiveInt());
            ew.putStr(1, rnd.nextChars(25));
            // you can use column index we looked up earlier
            ew.putDate(updateDateIndex, timestamp);
            // increment timestamp by 30 seconds
            timestamp += 30000;
            // append record to journal
            ew.append();
        }
        // commit all records at once
        // there is no limit on how many records can be in the same transaction
        writer.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Example 67 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class QueryCompiler method copyPartitioned.

private void copyPartitioned(RecordCursor cursor, JournalWriter w, CopyHelper helper, int tsIndex) throws JournalException {
    while (cursor.hasNext()) {
        Record r = cursor.next();
        JournalEntryWriter ew = w.entryWriter(r.getDate(tsIndex));
        helper.copy(r, ew);
        ew.append();
    }
}
Also used : JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Aggregations

JournalEntryWriter (com.questdb.store.JournalEntryWriter)67 JournalWriter (com.questdb.store.JournalWriter)59 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)47 Rnd (com.questdb.std.Rnd)43 Test (org.junit.Test)31 AbstractTest (com.questdb.test.tools.AbstractTest)28 BeforeClass (org.junit.BeforeClass)10 RecordCursor (com.questdb.common.RecordCursor)5 Record (com.questdb.common.Record)4 RecordSource (com.questdb.ql.RecordSource)4 StringSink (com.questdb.std.str.StringSink)4 BootstrapEnv (com.questdb.BootstrapEnv)3 ServerConfiguration (com.questdb.ServerConfiguration)3 ObjHashSet (com.questdb.std.ObjHashSet)3 Factory (com.questdb.store.factory.Factory)3 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)2 DoubleRecordSourceColumn (com.questdb.ql.ops.col.DoubleRecordSourceColumn)2 DoubleConstant (com.questdb.ql.ops.constant.DoubleConstant)2 AddDoubleOperator (com.questdb.ql.ops.plus.AddDoubleOperator)2 VirtualColumnRecordSource (com.questdb.ql.virtual.VirtualColumnRecordSource)2