use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class FirstIntGroupByFunctionFactoryTest method testAllNull.
@Test
public void testAllNull() 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();
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.sql.RecordCursor in project questdb by bluestreak01.
the class FirstLongGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f long)", 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 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(4689592037643856L, record.getLong(0));
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class FirstLongGroupByFunctionFactoryTest method testSomeNull.
@Test
public void testSomeNull() throws SqlException {
compiler.compile("create table tab (f long)", 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 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(100, record.getLong(0));
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class FirstTimestampGroupByFunctionFactoryTest method testSomeNull.
@Test
public void testSomeNull() throws SqlException {
compiler.compile("create table tab (f timestamp)", 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 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(100, record.getLong(0));
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class HaversineDistDegreeGroupByFunctionFactoryTest method test2DistancesAtEquator.
@Test
public void test2DistancesAtEquator() throws SqlException {
compiler.compile("create table tab1 (lat double, lon double, k timestamp)", sqlExecutionContext);
compiler.compile("create table tab2 (lat double, lon double, k timestamp)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab1", "testing")) {
double lonDegree = 0;
long ts = 0;
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow();
r.putDouble(0, 0);
r.putDouble(1, lonDegree);
r.putTimestamp(2, ts);
r.append();
lonDegree += 1;
ts += 10_000_000_000L;
}
w.commit();
}
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab2", "testing")) {
double lonDegree = -180;
long ts = 0;
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow();
r.putDouble(0, 0);
r.putDouble(1, lonDegree);
r.putTimestamp(2, ts);
r.append();
lonDegree += 1;
ts += 10_000_000_000L;
}
w.commit();
}
double distance1;
try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) from tab1", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
distance1 = record.getDouble(0);
}
}
double distance2;
try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) from tab2", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
distance2 = record.getDouble(0);
}
}
Assert.assertEquals(distance1, distance2, DELTA);
}
Aggregations