use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class O3Test method testAppendOrderStability.
private static void testAppendOrderStability(CairoEngine engine, SqlCompiler compiler, SqlExecutionContext sqlExecutionContext) throws SqlException {
compiler.compile("create table x (" + "seq long, " + "sym symbol, " + "ts timestamp" + "), index(sym) timestamp (ts) partition by DAY", sqlExecutionContext);
String[] symbols = { "AA", "BB" };
long[] seq = new long[symbols.length];
// insert some records in order
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "x", "testing")) {
long t = 0;
for (int i = 0; i < 1000; i++) {
TableWriter.Row r = w.newRow(t++);
int index = rnd.nextInt(1);
r.putLong(0, seq[index]++);
r.putSym(1, symbols[index]);
r.append();
}
w.commitWithLag();
// now do out of order
for (int i = 0; i < 100_000; i++) {
TableWriter.Row r;
// symbol 0
r = w.newRow(t + 1);
r.putLong(0, seq[0]++);
r.putSym(1, symbols[0]);
r.append();
r = w.newRow(t + 1);
r.putLong(0, seq[0]++);
r.putSym(1, symbols[0]);
r.append();
// symbol 1
r = w.newRow(t);
r.putLong(0, seq[1]++);
r.putSym(1, symbols[1]);
r.append();
r = w.newRow(t);
r.putLong(0, seq[1]++);
r.putSym(1, symbols[1]);
r.append();
t += 2;
}
w.commit();
}
// now verify that sequence did not get mixed up in the table
long[] actualSeq = new long[symbols.length];
try (RecordCursorFactory f = compiler.compile("x", sqlExecutionContext).getRecordCursorFactory();
RecordCursor cursor = f.getCursor(sqlExecutionContext)) {
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
int index = record.getInt(1);
Assert.assertEquals(record.getLong(0), actualSeq[index]++);
}
}
}
use of io.questdb.cairo.sql.RecordCursor 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.cairo.sql.RecordCursor 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.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class FirstIntGroupByFunctionFactoryTest 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 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.getInt(0));
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class FirstIntGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() 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.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(100, record.getInt(0));
}
}
}
Aggregations