use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class FirstDateGroupByFunctionFactoryTest method testFirstNull.
@Test
public void testFirstNull() throws SqlException {
compiler.compile("create table tab (f date)", 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.getLong(0));
}
}
}
use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class FirstDateGroupByFunctionFactoryTest 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 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.std.Rnd in project questdb by bluestreak01.
the class FloatGroupByFunctionsTest method testSampleBy.
@Test
public void testSampleBy() throws SqlException, NumericException {
sqlExecutionContext.setRandom(new Rnd());
try (TableModel tm = new TableModel(configuration, "tab", PartitionBy.DAY)) {
tm.timestamp("ts").col("ch", ColumnType.FLOAT);
createPopulateTable(tm, 100, "2020-01-01", 2);
}
assertSql("select ts, min(ch), max(ch), first(ch), last(ch), count() from tab sample by d", "ts\tmin\tmax\tfirst\tlast\tcount\n" + "2020-01-01T00:28:47.990000Z\t0.0010\t0.0510\t0.0010\t0.0510\t51\n" + "2020-01-02T00:28:47.990000Z\t0.0520\t0.1000\t0.0520\t0.1000\t49\n");
}
use of io.questdb.std.Rnd in project questdb by bluestreak01.
the class FloatGroupByFunctionsTest method testSampleByWithNulls.
@Test
public void testSampleByWithNulls() throws SqlException {
sqlExecutionContext.setRandom(new Rnd());
compiler.compile("create table tab as ( select rnd_float() ch from long_sequence(100) )", sqlExecutionContext);
assertSql("select min(ch), max(ch), first(ch), last(ch), count() from tab", "min\tmax\tfirst\tlast\tcount\n" + "0.0011\t0.9856\t0.6608\t0.7998\t100\n");
}
use of io.questdb.std.Rnd 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));
}
}
}
Aggregations