Search in sources :

Example 1 with RecordCursorFactory

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

the class TruncateTest method testTruncateOpenReader.

@Test
public void testTruncateOpenReader() throws Exception {
    assertMemoryLeak(() -> {
        createX(1_000_000);
        assertQuery("count\n" + "1000000\n", "select count() from x", null, false, true);
        try (RecordCursorFactory factory = compiler.compile("select * from x", sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                final Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    record.getInt(0);
                    record.getSym(1);
                    record.getDouble(2);
                }
            }
        }
        compiler.compile("truncate table 'x'", sqlExecutionContext);
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 2 with RecordCursorFactory

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

the class TruncateTest method testDropTableWithCachedPlan.

private void testDropTableWithCachedPlan(String query) throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table y as (" + "select timestamp_sequence(0, 1000000000) timestamp," + " rnd_symbol('a','b',null) symbol1 " + " from long_sequence(10)" + ") timestamp (timestamp)", sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile(query, sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                sink.clear();
                TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
            }
            compiler.compile("drop table y", sqlExecutionContext);
            compiler.compile("create table y as ( " + " select " + " timestamp_sequence('1970-01-01T02:30:00.000000Z', 1000000000L) timestamp " + " ,rnd_str('a','b','c', 'd', 'e', 'f',null) symbol2" + " ,rnd_str('a','b',null) symbol1" + " from long_sequence(10)" + ")", sqlExecutionContext);
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
                Assert.fail();
            } catch (ReaderOutOfDateException e) {
                TestUtils.assertContains(e.getFlyweightMessage(), "cannot be used because table schema has changed [table='y']");
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException)

Example 3 with RecordCursorFactory

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

the class UnionTest method testExceptOfLiterals.

@Test
public void testExceptOfLiterals() throws Exception {
    assertMemoryLeak(() -> {
        final String expected1 = "2020-04-21\t1\n" + "2020-04-21\t1\n";
        final String query1 = "select '2020-04-21', 1\n" + "except\n" + "select '2020-04-22', 2";
        try (RecordCursorFactory rcf = compiler.compile(query1, sqlExecutionContext).getRecordCursorFactory()) {
            assertCursor(expected1, rcf, true, false, false);
        }
        final String expected2 = "a\tb\n" + "2020-04-21\t1\n";
        final String query2 = "select '2020-04-21' a, 1 b\n" + "except\n" + "select '2020-04-22', 2";
        try (RecordCursorFactory rcf = compiler.compile(query2, sqlExecutionContext).getRecordCursorFactory()) {
            assertCursor(expected2, rcf, true, false, false);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) Test(org.junit.Test)

Example 4 with RecordCursorFactory

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

the class UnionTest method testIntersectOfLiterals.

@Test
public void testIntersectOfLiterals() throws Exception {
    assertMemoryLeak(() -> {
        final String expected1 = "2020-04-21\t1\n" + "2020-04-21\t1\n";
        final String query1 = "select '2020-04-21', 1\n" + "intersect\n" + "select '2020-04-21', 1";
        try (RecordCursorFactory rcf = compiler.compile(query1, sqlExecutionContext).getRecordCursorFactory()) {
            assertCursor(expected1, rcf, true, false, false);
        }
        final String expected2 = "a\tb\n" + "2020-04-21\t1\n";
        final String query2 = "select '2020-04-21' a, 1 b\n" + "intersect\n" + "select '2020-04-21', 1";
        try (RecordCursorFactory rcf = compiler.compile(query2, sqlExecutionContext).getRecordCursorFactory()) {
            assertCursor(expected2, rcf, true, false, false);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) Test(org.junit.Test)

Example 5 with RecordCursorFactory

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

the class UnionTest method testUnionAllOfSymbol.

// select distinct sym from a union all b
@Test
public void testUnionAllOfSymbol() throws Exception {
    assertMemoryLeak(() -> {
        final String expected = "t\n" + "CAR\n" + "CAR\n" + "VAN\n" + "PLANE\n" + "PLANE\n" + "PLANE\n" + "PLANE\n";
        final String expected2 = "t\n" + "CAR\n" + "VAN\n" + "PLANE\n" + "BICYCLE\n" + "SCOOTER\n";
        compiler.compile("CREATE TABLE x as " + "(SELECT " + " rnd_symbol('CAR', 'VAN', 'PLANE') t " + " FROM long_sequence(7) x)" + " partition by NONE", sqlExecutionContext);
        try (RecordCursorFactory rcf = compiler.compile("x", sqlExecutionContext).getRecordCursorFactory()) {
            assertCursor(expected, rcf, true, true, true);
        }
        SharedRandom.RANDOM.get().reset();
        compiler.compile("CREATE TABLE y as " + "(SELECT " + " rnd_symbol('PLANE', 'BICYCLE', 'SCOOTER') t " + " FROM long_sequence(7) x)" + " partition by NONE", sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile("select distinct t from x union all y", sqlExecutionContext).getRecordCursorFactory()) {
            assertCursor(expected2, factory, false, true, false);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) 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