Search in sources :

Example 31 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class MaxDoubleGroupByFunctionFactoryTest method testNonNull.

@Test
public void testNonNull() throws SqlException {
    compiler.compile("create table tab (f double)", 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.putDouble(0, rnd.nextDouble());
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select max(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.9856290845874263, record.getDouble(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 32 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class MaxDoubleGroupByFunctionFactoryTest 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 max(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 33 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class LastIntGroupByFunctionFactoryTest 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 last(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.INT_NaN, record.getInt(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 34 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class FirstDoubleGroupByFunctionFactoryTest method testNonNull.

@Test
public void testNonNull() throws SqlException {
    compiler.compile("create table tab (f double)", 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.putDouble(0, rnd.nextDouble());
            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(0.6607777894187332, record.getDouble(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 35 with TableWriter

use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.

the class GeoHashQueryTest method testDirectWrite.

@Test
public void testDirectWrite() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table t1 as (select " + "rnd_geohash(5) geo1," + "rnd_geohash(15) geo2," + "rnd_geohash(20) geo4," + "rnd_geohash(40) geo8," + "rnd_geohash(40) geo9," + "x " + "from long_sequence(0))", sqlExecutionContext);
        try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "t1", "test")) {
            for (int i = 0; i < 10; i++) {
                TableWriter.Row row = writer.newRow();
                row.putGeoStr(0, "qeustdb");
                row.putGeoHash(1, GeoHashes.fromString("qeustdb", 0, 2));
                row.putGeoHash(2, GeoHashes.fromString("qeustdb", 0, 4));
                row.putGeoHash(3, GeoHashes.fromString("qeustdb123456", 0, 8));
                row.putGeoHashDeg(4, -78.22, 113.22);
                row.putGeoHash(5, i);
                row.append();
            }
            writer.commit();
        }
        assertSql("t1", "geo1\tgeo2\tgeo4\tgeo8\tgeo9\tx\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t0\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t1\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t2\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t3\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t4\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t5\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t6\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t7\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t8\n" + "q\t0qe\tqeus\tqeustdb1\tnd0e02kr\t9\n");
    });
}
Also used : TableWriter(io.questdb.cairo.TableWriter) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) 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