use of io.questdb.cairo.sql.RecordCursorFactory 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.RecordCursorFactory 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.RecordCursorFactory 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.RecordCursorFactory 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.RecordCursorFactory in project questdb by bluestreak01.
the class SampleByTest method testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable.
@Test
public void testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 300000000) k" + " from" + " long_sequence(100)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
RecordCursorFactory factory = compiler.compile("select k, count() from x sample by 90m align to calendar time zone $1 with offset $2", sqlExecutionContext).getRecordCursorFactory();
String expectedMoscow = "k\tcount\n" + "1970-01-02T22:45:00.000000Z\t3\n" + "1970-01-03T00:15:00.000000Z\t18\n" + "1970-01-03T01:45:00.000000Z\t18\n" + "1970-01-03T03:15:00.000000Z\t18\n" + "1970-01-03T04:45:00.000000Z\t18\n" + "1970-01-03T06:15:00.000000Z\t18\n" + "1970-01-03T07:45:00.000000Z\t7\n";
String expectedPrague = "k\tcount\n" + "1970-01-02T23:10:00.000000Z\t8\n" + "1970-01-03T00:40:00.000000Z\t18\n" + "1970-01-03T02:10:00.000000Z\t18\n" + "1970-01-03T03:40:00.000000Z\t18\n" + "1970-01-03T05:10:00.000000Z\t18\n" + "1970-01-03T06:40:00.000000Z\t18\n" + "1970-01-03T08:10:00.000000Z\t2\n";
sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Moscow");
sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
assertCursor(expectedMoscow, cursor, factory.getMetadata(), true);
}
// invalid timezone
sqlExecutionContext.getBindVariableService().setStr(0, "Oopsie");
sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
try {
factory.getCursor(sqlExecutionContext);
Assert.fail();
} catch (SqlException e) {
Assert.assertEquals(67, e.getPosition());
TestUtils.assertContains(e.getFlyweightMessage(), "invalid timezone: Oopsie");
}
sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
sqlExecutionContext.getBindVariableService().setStr(1, "uggs");
try {
factory.getCursor(sqlExecutionContext);
Assert.fail();
} catch (SqlException e) {
Assert.assertEquals(82, e.getPosition());
TestUtils.assertContains(e.getFlyweightMessage(), "invalid offset: uggs");
}
sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
sqlExecutionContext.getBindVariableService().setStr(1, "00:10");
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
assertCursor(expectedPrague, cursor, factory.getMetadata(), true);
}
});
}
Aggregations