Search in sources :

Example 6 with JournalMetadata

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

the class JournalWriter method writeDiscardFile.

private void writeDiscardFile(long rowid) throws JournalException {
    if (discardTxtRaf == null) {
        try {
            discardTxtRaf = new RandomAccessFile(discardTxt, "rw");
            FileChannel ch = discardTxtRaf.getChannel();
            discardSink = new FlexBufferSink(ch.position(ch.size()), 1024 * 1024);
        } catch (IOException e) {
            LOG.error().$(e).$();
            throw JournalIOException.INSTANCE;
        }
    }
    JournalMetadata m = getMetadata();
    int p = Rows.toPartitionIndex(rowid);
    long row = Rows.toLocalRowID(rowid);
    long rowCount = 0;
    try {
        try {
            // partitions
            for (int n = getPartitionCount() - 1; p < n; p++) {
                final Partition partition = getPartition(n, true);
                // partition rows
                for (long r = row, psz = partition.size(); r < psz; r++) {
                    // partition columns
                    for (int c = 0, cc = m.getColumnCount(); c < cc; c++) {
                        switch(m.getColumnQuick(c).type) {
                            case ColumnType.DATE:
                                DateFormatUtils.appendDateTime(discardSink, partition.getLong(r, c));
                                break;
                            case ColumnType.DOUBLE:
                                Numbers.append(discardSink, partition.getDouble(r, c), 12);
                                break;
                            case ColumnType.FLOAT:
                                Numbers.append(discardSink, partition.getFloat(r, c), 4);
                                break;
                            case ColumnType.INT:
                                Numbers.append(discardSink, partition.getInt(r, c));
                                break;
                            case ColumnType.STRING:
                                partition.getStr(r, c, discardSink);
                                break;
                            case ColumnType.SYMBOL:
                                discardSink.put(partition.getSym(r, c));
                                break;
                            case ColumnType.SHORT:
                                Numbers.append(discardSink, partition.getShort(r, c));
                                break;
                            case ColumnType.LONG:
                                Numbers.append(discardSink, partition.getLong(r, c));
                                break;
                            case ColumnType.BYTE:
                                Numbers.append(discardSink, partition.getByte(r, c));
                                break;
                            case ColumnType.BOOLEAN:
                                discardSink.put(partition.getBool(r, c) ? "true" : "false");
                                break;
                            default:
                                break;
                        }
                        if (((++rowCount) & 7) == 0) {
                            discardSink.flush();
                        }
                    }
                }
            }
        } finally {
            discardSink.flush();
        }
    } catch (IOException e) {
        LOG.error().$(e).$();
        throw JournalIOException.INSTANCE;
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) FlexBufferSink(com.questdb.std.str.FlexBufferSink) JournalIOException(com.questdb.ex.JournalIOException) IOException(java.io.IOException)

Example 7 with JournalMetadata

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

the class DDLTests method testCreateDefaultPartitionBy.

@Test
public void testCreateDefaultPartitionBy() throws Exception {
    exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100");
    // validate journal
    try (Journal r = getFactory().reader("x")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(5, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertTrue(m.getColumn("a").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(1, m.getColumn("a").getBucketCount());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
        Assert.assertTrue(m.getColumn("z").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(63, m.getColumn("z").getBucketCount());
        Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType());
        Assert.assertTrue(m.getColumn("l").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(511, m.getColumn("l").getBucketCount());
        Assert.assertEquals(-1, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 8 with JournalMetadata

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

the class DDLTests method testCreateIndexedIntDefaultBuckets.

@Test
public void testCreateIndexedIntDefaultBuckets() throws Exception {
    exec("create table x (a INT index, b BYTE, t DATE, x SYMBOL) timestamp(t) partition by MONTH record hint 100");
    // validate journal
    try (Journal r = getFactory().reader("x")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(4, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertTrue(m.getColumn("a").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(1, m.getColumn("a").getBucketCount());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
        Assert.assertEquals(2, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy());
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 9 with JournalMetadata

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

the class DDLTests method testCreateIndexedString.

@Test
public void testCreateIndexedString() throws Exception {
    exec("create table x (a INT index, b BYTE, t DATE, z STRING index buckets 40) timestamp(t) partition by MONTH record hint 100");
    // validate journal
    try (Journal r = getFactory().reader("x")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(4, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertTrue(m.getColumn("a").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(1, m.getColumn("a").getBucketCount());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
        Assert.assertTrue(m.getColumn("z").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(63, m.getColumn("z").getBucketCount());
        Assert.assertEquals(2, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy());
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 10 with JournalMetadata

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

the class DDLTests method testCreateQuotedName.

@Test
public void testCreateQuotedName() throws Exception {
    exec("create table 'a b' (a INT index, b BYTE, t DATE, z STRING index buckets 40, l LONG index buckets 500) record hint 100");
    // validate journal
    try (Journal r = getFactory().reader("a b")) {
        Assert.assertNotNull(r);
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(5, m.getColumnCount());
        Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
        Assert.assertTrue(m.getColumn("a").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(1, m.getColumn("a").getBucketCount());
        Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
        Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
        Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
        Assert.assertTrue(m.getColumn("z").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(63, m.getColumn("z").getBucketCount());
        Assert.assertEquals(ColumnType.LONG, m.getColumn("l").getType());
        Assert.assertTrue(m.getColumn("l").isIndexed());
        // bucket is ceilPow2(value) - 1
        Assert.assertEquals(511, m.getColumn("l").getBucketCount());
        Assert.assertEquals(-1, m.getTimestampIndex());
        Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) Journal(com.questdb.store.Journal) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)29 Test (org.junit.Test)22 AbstractTest (com.questdb.test.tools.AbstractTest)19 Journal (com.questdb.store.Journal)14 JournalWriter (com.questdb.store.JournalWriter)5 JournalException (com.questdb.std.ex.JournalException)3 File (java.io.File)3 FactoryFullException (com.questdb.ex.FactoryFullException)2 JournalLockedException (com.questdb.ex.JournalLockedException)2 RetryLockException (com.questdb.ex.RetryLockException)2 ImportedColumnMetadata (com.questdb.parser.ImportedColumnMetadata)2 RecordSource (com.questdb.ql.RecordSource)2 Rnd (com.questdb.std.Rnd)2 Path (com.questdb.std.str.Path)2 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RecordColumnMetadata (com.questdb.common.RecordColumnMetadata)1 IncompatibleJournalException (com.questdb.ex.IncompatibleJournalException)1