Search in sources :

Example 91 with TableWriter

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)));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 92 with TableWriter

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));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 93 with TableWriter

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));
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 94 with TableWriter

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);
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) Record(io.questdb.cairo.sql.Record) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 95 with TableWriter

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);
        }
    }
}
Also used : TableWriter(io.questdb.cairo.TableWriter) RecordCursor(io.questdb.cairo.sql.RecordCursor) TableReader(io.questdb.cairo.TableReader) Test(org.junit.Test)

Aggregations

TableWriter (io.questdb.cairo.TableWriter)103 Test (org.junit.Test)88 RecordCursor (io.questdb.cairo.sql.RecordCursor)71 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)71 Record (io.questdb.cairo.sql.Record)70 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)68 Rnd (io.questdb.std.Rnd)23 TableReader (io.questdb.cairo.TableReader)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 EntryUnavailableException (io.questdb.cairo.EntryUnavailableException)7 ServerDisconnectException (io.questdb.network.ServerDisconnectException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 CairoConfiguration (io.questdb.cairo.CairoConfiguration)3 CairoEngine (io.questdb.cairo.CairoEngine)3 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)3 SqlCompiler (io.questdb.griffin.SqlCompiler)3 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)3 RecordCursorPrinter (io.questdb.cairo.RecordCursorPrinter)2 Path (io.questdb.std.str.Path)2 CyclicBarrier (java.util.concurrent.CyclicBarrier)2