use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class FirstDoubleGroupByFunctionFactoryTest method testAllNull.
@Test
public void testAllNull() throws SqlException {
compiler.compile("create table tab (f double)", 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.assertTrue(Double.isNaN(record.getDouble(0)));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class MinCharGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f char)", 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.putChar(0, rnd.nextChar());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(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(66, record.getChar(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class MinCharGroupByFunctionFactoryTest method testFirstNull.
@Test
public void testFirstNull() throws SqlException {
compiler.compile("create table tab (f char)", 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.putChar(0, rnd.nextChar());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(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(0, record.getChar(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class MinFloatGroupByFunctionFactoryTest method testFirstNull.
@Test
public void testFirstNull() throws SqlException {
compiler.compile("create table tab (f float)", 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.putFloat(0, rnd.nextFloat());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(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(0.0011075139045715332, record.getFloat(0), 0.0001);
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class PartitionDeleteTest method testBCSequence.
@Test
public void testBCSequence() throws SqlException, NumericException {
compiler.compile("create table events (sequence long, event binary, timestamp timestamp) timestamp(timestamp) partition by DAY", sqlExecutionContext);
engine.releaseAllWriters();
try (TableWriter w = new TableWriter(configuration, "events")) {
long ts = TimestampFormatUtils.parseTimestamp("2020-06-30T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow(ts);
r.putLong(0, i);
r.append();
}
ts = TimestampFormatUtils.parseTimestamp("2020-07-01T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow(ts);
r.putLong(0, 100 + i);
r.append();
}
ts = TimestampFormatUtils.parseTimestamp("2020-07-02T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row r = w.newRow(ts);
r.putLong(0, 200 + i);
r.append();
}
w.commit();
}
try (TableReader r = new TableReader(configuration, "events")) {
RecordCursor cursor = r.getCursor();
// noinspection StatementWithEmptyBody
while (cursor.hasNext()) {
}
try (TableWriter w = new TableWriter(configuration, "events")) {
long ts = TimestampFormatUtils.parseTimestamp("2020-07-02T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 250 + i);
row.append();
}
w.commit();
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-06-30T00:00:00.000000Z")));
r.reload();
cursor.toTop();
// noinspection StatementWithEmptyBody
while (cursor.hasNext()) {
}
ts = TimestampFormatUtils.parseTimestamp("2020-07-03T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 300 + i);
row.append();
}
w.commit();
ts = TimestampFormatUtils.parseTimestamp("2020-07-04T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 400 + i);
row.append();
}
w.commit();
ts = TimestampFormatUtils.parseTimestamp("2020-07-05T00:00:00.000000Z");
for (int i = 0; i < 10; i++) {
TableWriter.Row row = w.newRow(ts);
row.putLong(0, 500 + i);
row.append();
}
w.commit();
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-07-01T00:00:00.000000Z")));
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-07-02T00:00:00.000000Z")));
Assert.assertTrue(w.removePartition(TimestampFormatUtils.parseTimestamp("2020-07-03T00:00:00.000000Z")));
Assert.assertTrue(r.reload());
sink.clear();
cursor.toTop();
printer.print(cursor, r.getMetadata(), true, sink);
String expected = "sequence\tevent\ttimestamp\n" + "400\t\t2020-07-04T00:00:00.000000Z\n" + "401\t\t2020-07-04T00:00:00.000000Z\n" + "402\t\t2020-07-04T00:00:00.000000Z\n" + "403\t\t2020-07-04T00:00:00.000000Z\n" + "404\t\t2020-07-04T00:00:00.000000Z\n" + "405\t\t2020-07-04T00:00:00.000000Z\n" + "406\t\t2020-07-04T00:00:00.000000Z\n" + "407\t\t2020-07-04T00:00:00.000000Z\n" + "408\t\t2020-07-04T00:00:00.000000Z\n" + "409\t\t2020-07-04T00:00:00.000000Z\n" + "500\t\t2020-07-05T00:00:00.000000Z\n" + "501\t\t2020-07-05T00:00:00.000000Z\n" + "502\t\t2020-07-05T00:00:00.000000Z\n" + "503\t\t2020-07-05T00:00:00.000000Z\n" + "504\t\t2020-07-05T00:00:00.000000Z\n" + "505\t\t2020-07-05T00:00:00.000000Z\n" + "506\t\t2020-07-05T00:00:00.000000Z\n" + "507\t\t2020-07-05T00:00:00.000000Z\n" + "508\t\t2020-07-05T00:00:00.000000Z\n" + "509\t\t2020-07-05T00:00:00.000000Z\n";
TestUtils.assertEquals(expected, sink);
}
}
}
Aggregations