Search in sources :

Example 71 with RecordCursor

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

the class LikeFunctionFactoryTest method testNotLikeStringMatch.

@Test
public void testNotLikeStringMatch() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as (select rnd_str() name from long_sequence(2000))", sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile("select * from x where not name like 'XJ'", sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                sink.clear();
                printer.print(cursor, factory.getMetadata(), true, sink);
                Assert.assertNotEquals(sink.toString().indexOf("XJ"), -1);
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 72 with RecordCursor

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

the class LikeFunctionFactoryTest method testLikeStringPercentageAtEnd.

@Test
public void testLikeStringPercentageAtEnd() throws Exception {
    assertMemoryLeak(() -> {
        String sql = "create table x as (\n" + "select cast('ABCGE' as string) as name from long_sequence(1)\n" + "union\n" + "select cast('SBDHDJ' as string) as name from long_sequence(1)\n" + "union\n" + "select cast('BDGDGGG' as string) as name from long_sequence(1)\n" + "union\n" + "select cast('AAAAVVV' as string) as name from long_sequence(1)\n" + ")";
        compiler.compile(sql, sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile("select * from x where name like 'ABC%'", sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                sink.clear();
                printer.print(cursor, factory.getMetadata(), false, sink);
                Assert.assertEquals(sink.toString().replace("\n", ""), "ABCGE");
                sink.clear();
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 73 with RecordCursor

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

the class LikeFunctionFactoryTest method testLikeStringPercentageAtStartAndEnd.

@Test
public void testLikeStringPercentageAtStartAndEnd() throws Exception {
    assertMemoryLeak(() -> {
        String sql = "create table x as (\n" + "select cast('ABCGE' as string) as name from long_sequence(1)\n" + "union\n" + "select cast('SBDHDJ' as string) as name from long_sequence(1)\n" + "union\n" + "select cast('BDGDGGG' as string) as name from long_sequence(1)\n" + "union\n" + "select cast('AAAAVVV' as string) as name from long_sequence(1)\n" + ")";
        compiler.compile(sql, sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile("select * from x where name like '%BCG%'", sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                sink.clear();
                printer.print(cursor, factory.getMetadata(), false, sink);
                Assert.assertEquals(sink.toString().replace("\n", ""), "ABCGE");
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 74 with RecordCursor

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

the class LikeFunctionFactoryTest method testNotLikeCharacterMatch.

@Test
public void testNotLikeCharacterMatch() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as (select rnd_str() name from long_sequence(2000))", sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile("select * from x where not name like 'H'", sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                sink.clear();
                printer.print(cursor, factory.getMetadata(), true, sink);
                Assert.assertNotEquals(sink.toString().indexOf('H'), -1);
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 75 with RecordCursor

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

the class MinCharGroupByFunctionFactoryTest method testAllNull.

@Test
public void testAllNull() throws SqlException {
    compiler.compile("create table tab (f char)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 100; i > 10; i--) {
            TableWriter.Row r = w.newRow();
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select min(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(0, record.getChar(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

RecordCursor (io.questdb.cairo.sql.RecordCursor)174 Test (org.junit.Test)137 Record (io.questdb.cairo.sql.Record)123 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)108 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)87 TableWriter (io.questdb.cairo.TableWriter)71 Rnd (io.questdb.std.Rnd)29 LPSZ (io.questdb.std.str.LPSZ)10 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)7 SqlCompiler (io.questdb.griffin.SqlCompiler)6 DateFormat (io.questdb.std.datetime.DateFormat)6 Path (io.questdb.std.str.Path)6 StringSink (io.questdb.std.str.StringSink)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 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