use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class FirstTimestampGroupByFunctionFactoryTest method testFirstNull.
@Test
public void testFirstNull() throws SqlException {
compiler.compile("create table tab (f timestamp)", sqlExecutionContext);
final Rnd rnd = new Rnd();
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.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(Numbers.LONG_NaN, record.getTimestamp(0));
}
}
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class FirstTimestampGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f timestamp)", 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.RecordCursorFactory in project questdb by bluestreak01.
the class HaversineDistDegreeGroupByFunctionFactoryTest method testCircumferenceAtEquator.
@Test
public void testCircumferenceAtEquator() throws SqlException {
compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
double lonDegree = -180;
long ts = 0;
for (int i = 0; i < 360; 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 (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) 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(39919.53004981382, record.getDouble(0), DELTA);
}
}
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class HaversineDistDegreeGroupByFunctionFactoryTest method test10RowsAndNullAtEnd.
@Test
public void test10RowsAndNullAtEnd() throws SqlException {
compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
double latDegree = -5;
double lonDegree = -6;
long ts = 0;
TableWriter.Row r;
for (int i = 0; i < 10; i++) {
r = w.newRow();
r.putDouble(0, latDegree);
r.putDouble(1, lonDegree);
r.putTimestamp(2, ts);
r.append();
latDegree += 1;
lonDegree += 1;
ts += 10_000_000_000L;
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) 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(1414.545985354098, record.getDouble(0), DELTA);
}
}
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class HaversineDistDegreeGroupByFunctionFactoryTest method test10Rows.
@Test
public void test10Rows() throws SqlException {
compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
double latDegree = -5;
double lonDegree = -6;
long ts = 0;
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow();
r.putDouble(0, latDegree);
r.putDouble(1, lonDegree);
r.putTimestamp(2, ts);
r.append();
latDegree += 1;
lonDegree += 1;
ts += 10_000_000_000L;
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) 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(1414.545985354098, record.getDouble(0), DELTA);
}
}
}
Aggregations