Search in sources :

Example 51 with RecordCursorFactory

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

the class LikeFunctionFactoryTest method testLikeStringUnderscoreAndPercentage.

@Test
public void testLikeStringUnderscoreAndPercentage() 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 '_B%'", sqlExecutionContext).getRecordCursorFactory()) {
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                sink.clear();
                printer.print(cursor, factory.getMetadata(), false, sink);
                Assert.assertEquals(sink.toString().split("\n").length, 2);
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 52 with RecordCursorFactory

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

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

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

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

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