Search in sources :

Example 71 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class AppendRawUnordered method main.

public static void main(String[] args) throws JournalException, ParserException {
    if (args.length < 1) {
        System.out.println("Usage: AppendRawUnordered <path>");
        System.exit(1);
    }
    final String location = args[0];
    // factory can be reused in application and must be explicitly closed when no longer needed.
    try (Factory factory = new Factory(location, 1000, 1, 0)) {
        // 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) Factory(com.questdb.store.factory.Factory) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Example 72 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure 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 73 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class PlainTextStoringParser method createStructure.

private JournalStructure createStructure() {
    ObjList<ColumnMetadata> m = new ObjList<>(metadata.size());
    for (int i = 0, n = metadata.size(); i < n; i++) {
        ColumnMetadata cm = new ColumnMetadata();
        ImportedColumnMetadata im = metadata.getQuick(i);
        cm.name = im.name.toString();
        cm.type = im.importedColumnType;
        switch(cm.type) {
            case ColumnType.STRING:
                cm.size = cm.avgSize + 4;
                break;
            default:
                cm.size = ColumnType.sizeOf(cm.type);
                break;
        }
        m.add(cm);
    }
    return new JournalStructure(name, m);
}
Also used : ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata) ImportedColumnMetadata(com.questdb.parser.ImportedColumnMetadata) ImportedColumnMetadata(com.questdb.parser.ImportedColumnMetadata) JournalStructure(com.questdb.store.factory.configuration.JournalStructure)

Example 74 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class QueryCompiler method createStructure.

private JournalStructure createStructure(String location, RecordMetadata rm, CharSequenceObjHashMap<ColumnCastModel> castModels) throws ParserException {
    int n = rm.getColumnCount();
    ObjList<ColumnMetadata> m = new ObjList<>(n);
    for (int i = 0; i < n; i++) {
        ColumnMetadata cm = new ColumnMetadata();
        RecordColumnMetadata im = rm.getColumnQuick(i);
        cm.name = im.getName();
        int srcType = im.getType();
        ColumnCastModel castModel = castModels.get(cm.name);
        if (castModel != null) {
            validateTypeCastCompatibility(srcType, castModel);
            cm.type = castModel.getColumnType();
            if (cm.type == ColumnType.SYMBOL) {
                cm.distinctCountHint = Numbers.ceilPow2(castModel.getCount()) - 1;
            }
        } else {
            cm.type = srcType;
        }
        switch(cm.type) {
            case ColumnType.STRING:
                cm.size = cm.avgSize + 4;
                break;
            default:
                cm.size = ColumnType.sizeOf(cm.type);
                break;
        }
        m.add(cm);
    }
    return new JournalStructure(location, m).$ts(rm.getTimestampIndex());
}
Also used : ColumnMetadata(com.questdb.store.factory.configuration.ColumnMetadata) JournalStructure(com.questdb.store.factory.configuration.JournalStructure)

Aggregations

JournalStructure (com.questdb.store.factory.configuration.JournalStructure)74 JournalWriter (com.questdb.store.JournalWriter)60 JournalEntryWriter (com.questdb.store.JournalEntryWriter)47 Rnd (com.questdb.std.Rnd)43 Test (org.junit.Test)43 AbstractTest (com.questdb.test.tools.AbstractTest)40 BeforeClass (org.junit.BeforeClass)11 JournalException (com.questdb.std.ex.JournalException)9 Journal (com.questdb.store.Journal)9 JournalLockedException (com.questdb.ex.JournalLockedException)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 RetryLockException (com.questdb.ex.RetryLockException)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 BootstrapEnv (com.questdb.BootstrapEnv)4 ServerConfiguration (com.questdb.ServerConfiguration)4 FactoryFullException (com.questdb.ex.FactoryFullException)4 StringSink (com.questdb.std.str.StringSink)4 Factory (com.questdb.store.factory.Factory)4 FactoryClosedException (com.questdb.ex.FactoryClosedException)3