use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class MaxDoubleGroupByFunctionFactoryTest 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 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.assertEquals(0.9856290845874263, record.getDouble(0), 0.0001);
}
}
}
use of io.questdb.cairo.TableWriter 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.TableWriter 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.TableWriter 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.TableWriter in project questdb by bluestreak01.
the class GeoHashQueryTest method testDirectWrite.
@Test
public void testDirectWrite() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table t1 as (select " + "rnd_geohash(5) geo1," + "rnd_geohash(15) geo2," + "rnd_geohash(20) geo4," + "rnd_geohash(40) geo8," + "rnd_geohash(40) geo9," + "x " + "from long_sequence(0))", sqlExecutionContext);
try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "t1", "test")) {
for (int i = 0; i < 10; i++) {
TableWriter.Row row = writer.newRow();
row.putGeoStr(0, "qeustdb");
row.putGeoHash(1, GeoHashes.fromString("qeustdb", 0, 2));
row.putGeoHash(2, GeoHashes.fromString("qeustdb", 0, 4));
row.putGeoHash(3, GeoHashes.fromString("qeustdb123456", 0, 8));
row.putGeoHashDeg(4, -78.22, 113.22);
row.putGeoHash(5, i);
row.append();
}
writer.commit();
}
assertSql("t1", "geo1\tgeo2\tgeo4\tgeo8\tgeo9\tx\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t0\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t1\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t2\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t3\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t4\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t5\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t6\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t7\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t8\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t9\n");
});
}
Aggregations