Search in sources :

Example 21 with RecordCursorFactory

use of io.questdb.cairo.sql.RecordCursorFactory 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)

Example 22 with RecordCursorFactory

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

the class FirstDateGroupByFunctionFactoryTest method testFirstNull.

@Test
public void testFirstNull() throws SqlException {
    compiler.compile("create table tab (f date)", sqlExecutionContext);
    final Rnd rnd = new Rnd();
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        TableWriter.Row r = w.newRow();
        r.append();
        for (int i = 100; i > 10; i--) {
            r = w.newRow();
            r.putLong(0, rnd.nextLong());
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(Numbers.LONG_NaN, record.getLong(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 23 with RecordCursorFactory

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

the class FirstDateGroupByFunctionFactoryTest method testNonNull.

@Test
public void testNonNull() throws SqlException {
    compiler.compile("create table tab (f date)", sqlExecutionContext);
    final Rnd rnd = new Rnd();
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            r.putLong(0, rnd.nextLong());
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(4689592037643856L, record.getLong(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 24 with RecordCursorFactory

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

the class FirstIntGroupByFunctionFactoryTest method testSomeNull.

@Test
public void testSomeNull() throws SqlException {
    compiler.compile("create table tab (f int)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            if (i % 4 == 0) {
                r.putInt(0, i);
            }
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(100, record.getInt(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 25 with RecordCursorFactory

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

the class FirstIntGroupByFunctionFactoryTest method testNonNull.

@Test
public void testNonNull() throws SqlException {
    compiler.compile("create table tab (f int)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            r.putInt(0, i);
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals(100, record.getInt(0));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Aggregations

RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)136 Test (org.junit.Test)118 RecordCursor (io.questdb.cairo.sql.RecordCursor)108 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)89 Record (io.questdb.cairo.sql.Record)79 TableWriter (io.questdb.cairo.TableWriter)68 Rnd (io.questdb.std.Rnd)24 SqlCompiler (io.questdb.griffin.SqlCompiler)8 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)6 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)4 SqlException (io.questdb.griffin.SqlException)4 BaseConnection (org.postgresql.core.BaseConnection)4 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)3 Instant (de.invesdwin.util.time.Instant)3 FDate (de.invesdwin.util.time.date.FDate)3 FilesFacade (io.questdb.std.FilesFacade)3 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)3 CairoConfiguration (io.questdb.cairo.CairoConfiguration)2 CairoEngine (io.questdb.cairo.CairoEngine)2 CairoException (io.questdb.cairo.CairoException)2