Search in sources :

Example 11 with Record

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

the class RecordChainTest method testPseudoRandomAccess.

@Test
public void testPseudoRandomAccess() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 10000;
        try (RecordChain chain = new RecordChain(metadata, SIZE_4M)) {
            Record record = new TestRecord();
            LongList rows = new LongList();
            long o = -1L;
            for (int i = 0; i < N; i++) {
                o = chain.putRecord(record, o);
                rows.add(o);
            }
            Assert.assertEquals(N, rows.size());
            Record expected = new TestRecord();
            for (int i = 0, n = rows.size(); i < n; i++) {
                long row = rows.getQuick(i);
                Record actual = chain.recordAt(row);
                Assert.assertEquals(row, actual.getRowId());
                assertSame(expected, actual);
            }
            Record expected2 = new TestRecord();
            Record rec2 = chain.newRecord();
            for (int i = 0, n = rows.size(); i < n; i++) {
                long row = rows.getQuick(i);
                chain.recordAt(rec2, row);
                Assert.assertEquals(row, rec2.getRowId());
                assertSame(expected2, rec2);
            }
            Record expected3 = new TestRecord();
            Record rec3 = chain.getRecord();
            for (int i = 0, n = rows.size(); i < n; i++) {
                long row = rows.getQuick(i);
                chain.recordAt(rec3, row);
                Assert.assertEquals(row, rec3.getRowId());
                assertSame(expected3, rec3);
            }
        }
    });
}
Also used : Record(com.questdb.common.Record) LongList(com.questdb.std.LongList) Test(org.junit.Test)

Example 12 with Record

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

the class HashJoinRecordSource method advanceSlaveCursor.

private void advanceSlaveCursor() {
    Record rec = hashTableCursor.next();
    nullableRecord.set_null((byRowId ? slaveCursor.recordAt(rec.getLong(0)) : rec) == null);
}
Also used : Record(com.questdb.common.Record) FakeRecord(com.questdb.ql.join.hash.FakeRecord) NullableRecord(com.questdb.ql.NullableRecord)

Example 13 with Record

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

the class FilteredTableRecordCursorFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 100;
        // separate two symbol columns with primitive. It will make problems apparent if index does not shift correctly
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.STRING).col("b", ColumnType.SYMBOL).indexed(true, N / 4).col("i", ColumnType.INT).col("c", ColumnType.SYMBOL).indexed(true, N / 4).timestamp()) {
            CairoTestUtils.create(model);
        }
        final Rnd rnd = new Rnd();
        final String[] symbols = new String[N];
        final int M = 1000;
        final long increment = 1000000 * 60L * 4;
        for (int i = 0; i < N; i++) {
            symbols[i] = rnd.nextChars(8).toString();
        }
        rnd.reset();
        // prepare the data
        long timestamp = 0;
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < M; i++) {
                TableWriter.Row row = writer.newRow(timestamp += increment);
                row.putStr(0, rnd.nextChars(20));
                row.putSym(1, symbols[rnd.nextPositiveInt() % N]);
                row.putInt(2, rnd.nextInt());
                row.putSym(3, symbols[rnd.nextPositiveInt() % N]);
                row.append();
            }
            writer.commit();
        }
        try (Engine engine = new Engine(configuration)) {
            String value = symbols[N - 10];
            SymbolIndexRowCursorFactory symbolIndexRowCursorFactory = new SymbolIndexRowCursorFactory(engine, "x", "b", value);
            FullTableFrameCursorFactory dataFrameFactory = new FullTableFrameCursorFactory(engine, "x");
            FilteredTableRecordCursorFactory factory = new FilteredTableRecordCursorFactory(dataFrameFactory, symbolIndexRowCursorFactory);
            RecordCursor cursor = factory.getCursor();
            while (cursor.hasNext()) {
                Record record = cursor.next();
                TestUtils.assertEquals(value, record.getSym(1));
            }
            cursor.releaseCursor();
        }
    });
}
Also used : RecordCursor(com.questdb.common.RecordCursor) Rnd(com.questdb.std.Rnd) Record(com.questdb.common.Record) Test(org.junit.Test)

Example 14 with Record

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

the class AbstractOptimiserTest method assertString.

protected void assertString(String query, int columnIndex) throws ParserException {
    try (RecordSource rs = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
        RecordCursor cursor = rs.prepareCursor(FACTORY_CONTAINER.getFactory());
        try {
            while (cursor.hasNext()) {
                Record r = cursor.next();
                int len = r.getStrLen(columnIndex);
                CharSequence s = r.getFlyweightStr(columnIndex);
                if (s != null) {
                    CharSequence csB = r.getFlyweightStrB(columnIndex);
                    TestUtils.assertEquals(s, csB);
                    Assert.assertEquals(len, s.length());
                    Assert.assertFalse(s == csB);
                } else {
                    Assert.assertEquals(-1, len);
                    Assert.assertNull(r.getFlyweightStr(columnIndex));
                    Assert.assertNull(r.getFlyweightStrB(columnIndex));
                }
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record)

Example 15 with Record

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

the class AbstractOptimiserTest method assertSymbol.

public static void assertSymbol(String query, int columnIndex) throws ParserException {
    try (RecordSource src = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
        RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory());
        try {
            SymbolTable tab = cursor.getStorageFacade().getSymbolTable(columnIndex);
            while (cursor.hasNext()) {
                Record r = cursor.next();
                TestUtils.assertEquals(r.getSym(columnIndex), tab.value(r.getInt(columnIndex)));
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) SymbolTable(com.questdb.common.SymbolTable) 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