Search in sources :

Example 1 with BindVariableServiceImpl

use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.

the class WhereClauseParserTest method setUp1.

@Before
public void setUp1() {
    CairoEngine engine = new CairoEngine(configuration);
    bindVariableService = new BindVariableServiceImpl(configuration);
    compiler = new SqlCompiler(new CairoEngine(configuration));
    sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, bindVariableService, null, -1, null);
}
Also used : BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)

Example 2 with BindVariableServiceImpl

use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl 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 3 with BindVariableServiceImpl

use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.

the class MemoryLeakTest method populateUsersTable.

private void populateUsersTable(CairoEngine engine, int n) throws SqlException {
    try (final SqlCompiler compiler = new SqlCompiler(engine);
        final SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(configuration), null)) {
        compiler.compile("create table users (sequence long, event binary, timestamp timestamp, id long) timestamp(timestamp)", executionContext);
        long buffer = Unsafe.malloc(1024, MemoryTag.NATIVE_DEFAULT);
        try {
            try (TableWriter writer = engine.getWriter(executionContext.getCairoSecurityContext(), "users", "testing")) {
                // time can go backwards if asked too quickly, add I to offset the chance (on mac M1 at least)
                // call_j can yield a lower value than call_i thus resulting in an unordered
                long baseTimestamp = Os.currentTimeMicros();
                for (int i = 0; i < n; i++) {
                    // table, so we add i to make sure the timestamps are ordered
                    long sequence = 20 + i * 2L;
                    TableWriter.Row row = writer.newRow(baseTimestamp + i);
                    row.putLong(0, sequence);
                    row.putBin(1, buffer, 1024);
                    row.putLong(3, i);
                    row.append();
                }
                writer.commit();
            }
        } finally {
            Unsafe.free(buffer, 1024, MemoryTag.NATIVE_DEFAULT);
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)

Example 4 with BindVariableServiceImpl

use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.

the class LineTcpReceiverTest method testWithColumnAsReservedKeyword.

@Test
public void testWithColumnAsReservedKeyword() throws Exception {
    try (SqlCompiler compiler = new SqlCompiler(engine);
        SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(configuration), null, -1, null)) {
        String expected = "out\ttimestamp\tin\n" + "1.0\t1989-12-31T23:26:40.000000Z\tNaN\n" + "NaN\t1990-01-01T00:00:00.000000Z\t2.0\n" + "NaN\t1990-01-01T02:13:20.000000Z\t3.0\n" + "NaN\t1990-01-01T05:00:00.000000Z\t4.0\n";
        runInContext((receiver) -> {
            String lineData = "up out=1.0 631150000000000000\n" + "up in=2.0 631152000000000000\n" + "up in=3.0 631160000000000000\n" + "up in=4.0 631170000000000000\n";
            sendLinger(receiver, lineData, "up");
        });
        TestUtils.assertSql(compiler, sqlExecutionContext, "up", sink, expected);
    }
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl) Test(org.junit.Test)

Example 5 with BindVariableServiceImpl

use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.

the class LineTcpReceiverTest method testTableTableIdChangedOnRecreate.

@Test
public void testTableTableIdChangedOnRecreate() throws Exception {
    try (SqlCompiler compiler = new SqlCompiler(engine);
        SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(configuration), null, -1, null)) {
        compiler.compile("create table weather as (" + "select x as windspeed," + "x*2 as timetocycle, " + "cast(x as timestamp) as ts " + "from long_sequence(2)) timestamp(ts) ", sqlExecutionContext);
        CompiledQuery cq = compiler.compile("weather", sqlExecutionContext);
        try (RecordCursorFactory cursorFactory = cq.getRecordCursorFactory()) {
            try (RecordCursor cursor = cursorFactory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, cursorFactory.getMetadata(), true, sink, printer);
                TestUtils.assertEquals("windspeed\ttimetocycle\tts\n" + "1\t2\t1970-01-01T00:00:00.000001Z\n" + "2\t4\t1970-01-01T00:00:00.000002Z\n", sink);
            }
            compiler.compile("drop table weather", sqlExecutionContext);
            runInContext((receiver) -> {
                String lineData = "weather windspeed=1.0 631150000000000000\n" + "weather windspeed=2.0 631152000000000000\n" + "weather timetocycle=0.0,windspeed=3.0 631160000000000000\n" + "weather windspeed=4.0 631170000000000000\n";
                sendLinger(receiver, lineData, "weather");
            });
            try (RecordCursor cursor = cursorFactory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, cursorFactory.getMetadata(), true, sink, printer);
                Assert.fail();
            } catch (ReaderOutOfDateException ignored) {
            }
        }
    }
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException) CompiledQuery(io.questdb.griffin.CompiledQuery) Test(org.junit.Test)

Aggregations

BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)9 SqlCompiler (io.questdb.griffin.SqlCompiler)4 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)4 Test (org.junit.Test)3 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)2 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)2 TableWriter (io.questdb.cairo.TableWriter)1 BindVariableService (io.questdb.cairo.sql.BindVariableService)1 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)1 RecordCursor (io.questdb.cairo.sql.RecordCursor)1 CompiledQuery (io.questdb.griffin.CompiledQuery)1 FilesFacade (io.questdb.std.FilesFacade)1 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)1 DateFormat (io.questdb.std.datetime.DateFormat)1 TimestampFormatCompiler (io.questdb.std.datetime.microtime.TimestampFormatCompiler)1 StringSink (io.questdb.std.str.StringSink)1 File (java.io.File)1 BeforeClass (org.junit.BeforeClass)1