Search in sources :

Example 1 with PageFrameCursor

use of io.questdb.cairo.sql.PageFrameCursor in project questdb by bluestreak01.

the class ReplDataAccessTest method testSimple.

@Test
public void testSimple() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as (select" + " rnd_int() a," + " rnd_str() b," + " timestamp_sequence(0, 100000000) t" + " from long_sequence(1000)" + ") timestamp (t) partition by DAY", sqlExecutionContext);
        TestUtils.printSql(compiler, sqlExecutionContext, "select b from x", sink);
        final StringSink actualSink = new StringSink();
        // header
        actualSink.put("b\n");
        try (RecordCursorFactory factory = compiler.compile("x", sqlExecutionContext).getRecordCursorFactory()) {
            // test that we can read string column without using index
            try (PageFrameCursor pageFrameCursor = factory.getPageFrameCursor(sqlExecutionContext)) {
                PageFrame frame;
                while ((frame = pageFrameCursor.next()) != null) {
                    long varAddress = frame.getPageAddress(1);
                    long fixAddress = frame.getIndexPageAddress(1);
                    long topOfVarAddress = varAddress;
                    long count = frame.getPartitionHi() - frame.getPartitionLo();
                    while (count > 0) {
                        // validate that index column has correct offsets
                        Assert.assertEquals(varAddress - topOfVarAddress, Unsafe.getUnsafe().getLong(fixAddress));
                        fixAddress += 8;
                        // string len
                        int len = Unsafe.getUnsafe().getInt(varAddress);
                        varAddress += 4;
                        if (len != -1) {
                            for (int i = 0; i < len; i++) {
                                actualSink.put(Unsafe.getUnsafe().getChar(varAddress + i * 2L));
                            }
                            varAddress += len * 2L;
                        }
                        actualSink.put('\n');
                        count--;
                    }
                    Assert.assertEquals(varAddress - topOfVarAddress, frame.getPageSize(1));
                }
                TestUtils.assertEquals(sink, actualSink);
            }
        }
    });
}
Also used : PageFrameCursor(io.questdb.cairo.sql.PageFrameCursor) PageFrame(io.questdb.cairo.sql.PageFrame) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Aggregations

PageFrame (io.questdb.cairo.sql.PageFrame)1 PageFrameCursor (io.questdb.cairo.sql.PageFrameCursor)1 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)1 StringSink (io.questdb.std.str.StringSink)1 Test (org.junit.Test)1