use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class MaxDoubleGroupByFunctionFactoryTest method testAllNull.
@Test
public void testAllNull() throws SqlException {
compiler.compile("create table tab (f double)", 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 max(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.assertTrue(Double.isNaN(record.getDouble(0)));
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class LastIntGroupByFunctionFactoryTest method testSomeNull.
@Test
public void testSomeNull() throws SqlException {
compiler.compile("create table tab (f int)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
if (i % 4 == 0) {
r.putInt(0, i);
}
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select last(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(Numbers.INT_NaN, record.getInt(0));
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class FirstDoubleGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f double)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
r.putDouble(0, rnd.nextDouble());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select first(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.6607777894187332, record.getDouble(0), 0.0001);
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class PrefixedClassCatalogueFunctionFactoryTest method testSimple.
@Test
public void testSimple() throws Exception {
assertMemoryLeak(() -> {
sink.clear();
try (RecordCursorFactory factory = compiler.compile("select * from pg_catalog.pg_class() order by relname", sqlExecutionContext).getRecordCursorFactory()) {
RecordCursor cursor = factory.getCursor(sqlExecutionContext);
try {
printer.print(cursor, factory.getMetadata(), true, sink);
TestUtils.assertEquals("relname\trelnamespace\trelkind\trelowner\toid\trelpartbound\n" + "pg_class\t11\tr\t0\t1259\t\n", sink);
compiler.compile("create table xyz (a int)", sqlExecutionContext);
cursor.close();
cursor = factory.getCursor(sqlExecutionContext);
sink.clear();
printer.print(cursor, factory.getMetadata(), true, sink);
TestUtils.assertEquals("relname\trelnamespace\trelkind\trelowner\toid\trelpartbound\n" + "pg_class\t11\tr\t0\t1259\t\n" + "xyz\t2200\tr\t0\t1\t\n", sink);
try (Path path = new Path()) {
path.of(configuration.getRoot());
path.concat("test").$();
Assert.assertEquals(0, FilesFacadeImpl.INSTANCE.mkdirs(path, 0));
}
compiler.compile("create table автомобилей (b double)", sqlExecutionContext);
cursor.close();
cursor = factory.getCursor(sqlExecutionContext);
sink.clear();
printer.print(cursor, factory.getMetadata(), true, sink);
TestUtils.assertEquals("relname\trelnamespace\trelkind\trelowner\toid\trelpartbound\n" + "pg_class\t11\tr\t0\t1259\t\n" + "xyz\t2200\tr\t0\t1\t\n" + "автомобилей\t2200\tr\t0\t2\t\n", sink);
compiler.compile("drop table автомобилей;", sqlExecutionContext);
cursor.close();
cursor = factory.getCursor(sqlExecutionContext);
sink.clear();
printer.print(cursor, factory.getMetadata(), true, sink);
TestUtils.assertEquals("relname\trelnamespace\trelkind\trelowner\toid\trelpartbound\n" + "pg_class\t11\tr\t0\t1259\t\n" + "xyz\t2200\tr\t0\t1\t\n", sink);
} finally {
cursor.close();
}
}
});
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class UnionRecordCursorFactory method getCursor.
@Override
public RecordCursor getCursor(SqlExecutionContext executionContext) throws SqlException {
RecordCursor masterCursor = null;
RecordCursor slaveCursor = null;
try {
masterCursor = masterFactory.getCursor(executionContext);
slaveCursor = slaveFactory.getCursor(executionContext);
cursor.of(masterCursor, slaveCursor, executionContext);
return cursor;
} catch (Throwable ex) {
Misc.free(masterCursor);
Misc.free(slaveCursor);
throw ex;
}
}
Aggregations