Search in sources :

Example 6 with Journal

use of com.questdb.store.Journal 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 7 with Journal

use of com.questdb.store.Journal 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 8 with Journal

use of com.questdb.store.Journal 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)

Example 9 with Journal

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

the class DDLTests method testCreateAsSelectAll.

@Test
public void testCreateAsSelectAll() throws Exception {
    int N = 50;
    try (JournalWriter w = compiler.createWriter(getFactory(), "create table x (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING, y BOOLEAN) timestamp(t) record hint 100")) {
        Rnd rnd = new Rnd();
        long t = DateFormatUtils.parseDateTime("2016-01-10T00:00:00.000Z");
        for (int i = 0; i < N; i++) {
            JournalEntryWriter ew = w.entryWriter(t += Dates.DAY_MILLIS);
            ew.putInt(0, i);
            ew.put(1, (byte) rnd.nextInt());
            ew.putShort(2, (short) rnd.nextInt());
            ew.putLong(3, rnd.nextLong());
            ew.putFloat(4, rnd.nextFloat());
            ew.putDouble(5, rnd.nextDouble());
            ew.putDate(6, rnd.nextLong());
            ew.putNull(7);
            ew.putSym(9, rnd.nextChars(1));
            ew.putStr(10, rnd.nextChars(10));
            ew.putBool(11, rnd.nextBoolean());
            ew.append();
        }
        w.commit();
    }
    exec("create table y as (x) partition by MONTH");
    try (Journal r = getFactory().reader("y")) {
        Assert.assertEquals(2, r.getPartitionCount());
    }
    int count = 0;
    try (RecordSource rs = compiler.compile(getFactory(), "y")) {
        RecordCursor cursor = rs.prepareCursor(getFactory());
        try {
            Rnd rnd = new Rnd();
            while (cursor.hasNext()) {
                Record rec = cursor.next();
                Assert.assertEquals(count, rec.getInt(0));
                Assert.assertTrue((byte) rnd.nextInt() == rec.getByte(1));
                Assert.assertEquals((short) rnd.nextInt(), rec.getShort(2));
                Assert.assertEquals(rnd.nextLong(), rec.getLong(3));
                Assert.assertEquals(rnd.nextFloat(), rec.getFloat(4), 0.00001f);
                Assert.assertEquals(rnd.nextDouble(), rec.getDouble(5), 0.00000000001);
                Assert.assertEquals(rnd.nextLong(), rec.getDate(6));
                Assert.assertNull(rec.getBin(7));
                TestUtils.assertEquals(rnd.nextChars(1), rec.getSym(9));
                TestUtils.assertEquals(rnd.nextChars(10), rec.getFlyweightStr(10));
                Assert.assertEquals(rnd.nextBoolean(), rec.getBool(11));
                count++;
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordCursor(com.questdb.common.RecordCursor) Journal(com.questdb.store.Journal) Record(com.questdb.common.Record) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 10 with Journal

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

the class DDLTests method testCreateIndexWithSuffixDefaultPartition.

@Test
public void testCreateIndexWithSuffixDefaultPartition() throws Exception {
    exec("create table x (a INT, b BYTE, t DATE, x SYMBOL), index(a buckets 25), index(x) timestamp(t) 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(31, 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.assertTrue(m.getColumn("x").isIndexed());
        Assert.assertEquals(2, 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

Journal (com.questdb.store.Journal)27 Test (org.junit.Test)24 AbstractTest (com.questdb.test.tools.AbstractTest)23 JournalMetadata (com.questdb.store.factory.configuration.JournalMetadata)14 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)9 RetryLockException (com.questdb.ex.RetryLockException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 FactoryFullException (com.questdb.ex.FactoryFullException)4 JournalLockedException (com.questdb.ex.JournalLockedException)4 JournalException (com.questdb.std.ex.JournalException)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 JournalDeltaProducer (com.questdb.net.ha.producer.JournalDeltaProducer)2 RecordSource (com.questdb.ql.RecordSource)2 Rnd (com.questdb.std.Rnd)2 File (java.io.File)2 BootstrapEnv (com.questdb.BootstrapEnv)1 ServerConfiguration (com.questdb.ServerConfiguration)1 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1