Search in sources :

Example 6 with Record

use of com.questdb.common.Record 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 7 with Record

use of com.questdb.common.Record in project questdb by bluestreak01.

the class RecordKeyCopierCompilerTest method testCompiler.

@Test
public void testCompiler() throws Exception {
    try (JournalWriter w = compiler.createWriter(FACTORY_CONTAINER.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) partition by MONTH record hint 100")) {
        JournalEntryWriter ew = w.entryWriter();
        IntList keyColumns = new IntList();
        ew.putInt(0, 12345);
        keyColumns.add(0);
        ew.put(1, (byte) 128);
        keyColumns.add(1);
        ew.putShort(2, (short) 6500);
        keyColumns.add(2);
        ew.putLong(3, 123456789);
        keyColumns.add(3);
        ew.putFloat(4, 0.345f);
        keyColumns.add(4);
        ew.putDouble(5, 0.123456789);
        keyColumns.add(5);
        ew.putDate(6, 10000000000L);
        keyColumns.add(6);
        ew.putSym(9, "xyz");
        keyColumns.add(9);
        ew.putStr(10, "abc");
        keyColumns.add(10);
        ew.putBool(11, true);
        keyColumns.add(11);
        ew.append();
        w.commit();
        try (RecordSource src = compileSource("x")) {
            RecordKeyCopierCompiler cc = new RecordKeyCopierCompiler(new BytecodeAssembler());
            RecordKeyCopier copier = cc.compile(src.getMetadata(), keyColumns);
            IntList valueTypes = new IntList();
            valueTypes.add(ColumnType.DOUBLE);
            MetadataTypeResolver metadataTypeResolver = new MetadataTypeResolver();
            TypeListResolver typeListResolver = new TypeListResolver();
            try (DirectMap map = new DirectMap(1024, metadataTypeResolver.of(src.getMetadata(), keyColumns), typeListResolver.of(valueTypes))) {
                RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory());
                try {
                    while (cursor.hasNext()) {
                        Record r = cursor.next();
                        DirectMap.KeyWriter kw = map.keyWriter();
                        copier.copy(r, kw);
                        DirectMapValues val = map.getOrCreateValues();
                        val.putDouble(0, 5000.01);
                    }
                    cursor.toTop();
                    while (cursor.hasNext()) {
                        Record r = cursor.next();
                        DirectMap.KeyWriter kw = map.keyWriter();
                        copier.copy(r, kw);
                        Assert.assertEquals(map.getValues().getDouble(0), 5000.01, 0.00000001);
                    }
                } finally {
                    cursor.releaseCursor();
                }
            }
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordCursor(com.questdb.common.RecordCursor) BytecodeAssembler(com.questdb.std.BytecodeAssembler) IntList(com.questdb.std.IntList) RecordSource(com.questdb.ql.RecordSource) Record(com.questdb.common.Record) JournalEntryWriter(com.questdb.store.JournalEntryWriter) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 8 with Record

use of com.questdb.common.Record in project questdb by bluestreak01.

the class RecordChainTest method testWriteAndRead.

@Test
public void testWriteAndRead() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 100000;
        Record record = new TestRecord();
        try (RecordChain chain = new RecordChain(metadata, 4 * 1024 * 1024L)) {
            long o = -1L;
            long t = 0;
            for (int i = -N; i < N; i++) {
                if (i == 0) {
                    t = System.nanoTime();
                }
                o = chain.putRecord(record, o);
            }
            System.out.println("RecordChain append time: " + (System.nanoTime() - t));
            assertChain(chain, new TestRecord(), N * 2);
            assertChain(chain, new TestRecord(), N * 2);
        }
    });
}
Also used : Record(com.questdb.common.Record) Test(org.junit.Test)

Example 9 with Record

use of com.questdb.common.Record in project questdb by bluestreak01.

the class RecordChainTest method testClear.

@Test
public void testClear() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        Record record = new TestRecord();
        final int N = 10000;
        try (RecordChain chain = new RecordChain(metadata, SIZE_4M)) {
            Assert.assertFalse(chain.hasNext());
            populateChain(chain, record, N);
            chain.toTop();
            Assert.assertTrue(chain.hasNext());
            chain.clear();
            chain.toTop();
            Assert.assertFalse(chain.hasNext());
        }
    });
}
Also used : Record(com.questdb.common.Record) Test(org.junit.Test)

Example 10 with Record

use of com.questdb.common.Record in project questdb by bluestreak01.

the class RecordChainTest method testChainReuseWithClearFunction.

private void testChainReuseWithClearFunction(ClearFunc clear) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        Record record = new TestRecord();
        Record expected = new TestRecord();
        final int N = 10000;
        try (RecordChain chain = new RecordChain(metadata, 4 * 1024 * 1024L)) {
            populateChain(chain, record, N);
            assertChain(chain, expected, N);
            clear.clear(chain);
            populateChain(chain, record, N);
            assertChain(chain, expected, N);
        }
    });
}
Also used : Record(com.questdb.common.Record)

Aggregations

Record (com.questdb.common.Record)29 RecordCursor (com.questdb.common.RecordCursor)19 Test (org.junit.Test)13 RecordSource (com.questdb.ql.RecordSource)10 JournalWriter (com.questdb.store.JournalWriter)5 AbstractTest (com.questdb.test.tools.AbstractTest)5 FakeRecord (com.questdb.ql.join.hash.FakeRecord)4 JournalEntryWriter (com.questdb.store.JournalEntryWriter)4 NullableRecord (com.questdb.ql.NullableRecord)3 Rnd (com.questdb.std.Rnd)3 SymbolTable (com.questdb.common.SymbolTable)2 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)2 LongList (com.questdb.std.LongList)2 RedBlackTree (com.questdb.std.RedBlackTree)2 ArrayList (java.util.ArrayList)2 RecordCursorFactory (com.questdb.cairo.sql.RecordCursorFactory)1 QueryCompiler (com.questdb.parser.sql.QueryCompiler)1 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)1 AsOfPartitionedJoinRecordSource (com.questdb.ql.join.AsOfPartitionedJoinRecordSource)1 BytecodeAssembler (com.questdb.std.BytecodeAssembler)1