use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class FirstIntGroupByFunctionFactoryTest method testFirstNull.
@Test
public void testFirstNull() throws SqlException {
compiler.compile("create table tab (f int)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
TableWriter.Row r = w.newRow();
r.append();
for (int i = 100; i > 10; i--) {
r = w.newRow();
r.putInt(0, i);
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(Numbers.INT_NaN, record.getInt(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class LastDateGroupByFunctionFactoryTest method testSomeNull.
@Test
public void testSomeNull() throws SqlException {
compiler.compile("create table tab (f date)", 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.putLong(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.LONG_NaN, record.getDate(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class LastDateGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f date)", 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.putLong(0, rnd.nextLong());
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(-6919361415374675248L, record.getLong(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class LastDateGroupByFunctionFactoryTest method testAllNull.
@Test
public void testAllNull() throws SqlException {
compiler.compile("create table tab (f date)", 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 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.LONG_NaN, record.getLong(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class GeoHashQueryTest method testDirectWriteEmpty.
@Test
public void testDirectWriteEmpty() 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," + "x " + "from long_sequence(0))", sqlExecutionContext);
try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "t1", "test")) {
for (int i = 0; i < 2; i++) {
TableWriter.Row row = writer.newRow();
row.putGeoHash(4, i);
row.append();
}
writer.commit();
}
assertSql("t1", "geo1\tgeo2\tgeo4\tgeo8\tx\n" + "\t\t\t\t0\n" + "\t\t\t\t1\n");
});
}
Aggregations