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);
}
}
});
}
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();
}
}
});
}
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");
}
}
});
}
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);
}
}
});
}
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));
}
}
}
Aggregations