Search in sources :

Example 11 with RecordCursorFactory

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

the class JoinTest method testCrossTripleOverflow.

@Test
public void testCrossTripleOverflow() throws Exception {
    assertMemoryLeak(() -> {
        final CompiledQuery cq = compiler.compile("select * from long_sequence(1000000000) a cross join long_sequence(1000000000) b cross join long_sequence(1000000000) c", sqlExecutionContext);
        final RecordCursorFactory factory = cq.getRecordCursorFactory();
        try {
            Assert.assertNotNull(factory);
            sink.clear();
            printer.printHeader(factory.getMetadata(), sink);
            TestUtils.assertEquals("x\tx1\tx2\n", sink);
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                Assert.assertEquals(Long.MAX_VALUE, cursor.size());
            }
        } finally {
            Misc.free(factory);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Test(org.junit.Test)

Example 12 with RecordCursorFactory

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

the class LatestByParallelTest method assertQuery.

private static void assertQuery(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, String expected, String ddl, String query) throws SqlException {
    compiler.compile(ddl, sqlExecutionContext);
    CompiledQuery cc = compiler.compile(query, sqlExecutionContext);
    RecordCursorFactory factory = cc.getRecordCursorFactory();
    try {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            TestUtils.assertCursor(expected, cursor, factory.getMetadata(), true, sink);
        }
    } finally {
        Misc.free(factory);
    }
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor)

Example 13 with RecordCursorFactory

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

the class MemoryLeakTest method testQuestDbForLeaks.

@Test
public void testQuestDbForLeaks() throws Exception {
    assertMemoryLeak(() -> {
        int N = 1_000_000;
        populateUsersTable(engine, N);
        try (SqlCompiler compiler = new SqlCompiler(engine)) {
            final BindVariableService bindVariableService = new BindVariableServiceImpl(configuration);
            bindVariableService.setLong("low", 0L);
            bindVariableService.setLong("high", 0L);
            try (final SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, bindVariableService, null)) {
                StringSink sink = new StringSink();
                sink.clear();
                sink.put("users");
                sink.put(" latest by id where sequence > :low and sequence < :high");
                try (RecordCursorFactory rcf = compiler.compile(sink, executionContext).getRecordCursorFactory()) {
                    bindVariableService.setLong("low", 0);
                    bindVariableService.setLong("high", N + 1);
                    Misc.free(rcf.getCursor(executionContext));
                }
            }
        } finally {
            Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
            engine.clear();
            Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl) BindVariableService(io.questdb.cairo.sql.BindVariableService) StringSink(io.questdb.std.str.StringSink) Test(org.junit.Test)

Example 14 with RecordCursorFactory

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

the class O3CommitLagTest method insertUncommitted.

private void insertUncommitted(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, String sql, TableWriter writer) throws SqlException {
    minTimestamp = Long.MAX_VALUE;
    maxTimestamp = Long.MIN_VALUE;
    try (RecordCursorFactory factory = compiler.compile(sql, sqlExecutionContext).getRecordCursorFactory()) {
        RecordMetadata metadata = factory.getMetadata();
        int timestampIndex = writer.getMetadata().getTimestampIndex();
        EntityColumnFilter toColumnFilter = new EntityColumnFilter();
        toColumnFilter.of(metadata.getColumnCount());
        if (null == copier) {
            copier = SqlCompiler.assembleRecordToRowCopier(new BytecodeAssembler(), metadata, writer.getMetadata(), toColumnFilter);
        }
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            final Record record = cursor.getRecord();
            while (cursor.hasNext()) {
                long timestamp = record.getTimestamp(timestampIndex);
                if (timestamp > maxTimestamp) {
                    maxTimestamp = timestamp;
                }
                if (timestamp < minTimestamp) {
                    minTimestamp = timestamp;
                }
                Row row = writer.newRow(timestamp);
                copier.copy(record, row);
                row.append();
            }
        }
    }
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Row(io.questdb.cairo.TableWriter.Row) BytecodeAssembler(io.questdb.std.BytecodeAssembler)

Example 15 with RecordCursorFactory

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

the class KeyedAggregationTest method testIntSymbolSumAddKeyTimeRange.

@Test
public void testIntSymbolSumAddKeyTimeRange() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table tab as (select rnd_symbol('s1','s2','s3', null) s1, rnd_double(2) val, timestamp_sequence(0, 1000000) t from long_sequence(1000000)) timestamp(t) partition by DAY", sqlExecutionContext);
        compiler.compile("alter table tab add column s2 symbol cache", sqlExecutionContext);
        compiler.compile("insert into tab select rnd_symbol('s1','s2','s3', null), rnd_double(2), timestamp_sequence(cast('1970-01-13T00:00:00.000000Z' as timestamp), 1000000), rnd_symbol('a1','a2','a3', null) s2 from long_sequence(1000000)", sqlExecutionContext);
        // test with key falling within null columns
        try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-04T12:01' and t < '1970-01-07T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
            Record[] expected = new Record[] { new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return null;
                }

                @Override
                public double getDouble(int col) {
                    return 106413.99769604905;
                }
            } };
            assertCursorRawRecords(expected, factory, false, true);
        }
        // / test key on overlap
        try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-12T12:01' and t < '1970-01-14T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
            Record[] expected = new Record[] { new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return null;
                }

                @Override
                public double getDouble(int col) {
                    return 15636.977658744854;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a1";
                }

                @Override
                public double getDouble(int col) {
                    return 13073.816187889399;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a2";
                }

                @Override
                public double getDouble(int col) {
                    return 13240.269899560482;
                }
            }, new Record() {

                @Override
                public CharSequence getSym(int col) {
                    return "a3";
                }

                @Override
                public double getDouble(int col) {
                    return 13223.021189180576;
                }
            } };
            assertCursorRawRecords(expected, factory, false, true);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) Record(io.questdb.cairo.sql.Record) 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