Search in sources :

Example 91 with RecordCursorFactory

use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.

the class HaversineDistDegreeGroupByFunctionFactoryTest method testOneNullInMiddle.

@Test
public void testOneNullInMiddle() throws SqlException {
    compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        TableWriter.Row r = w.newRow();
        r.putDouble(0, 1);
        r.putDouble(1, 2);
        r.putTimestamp(2, 10_000_000_000L);
        r.append();
        r = w.newRow();
        r.append();
        r = w.newRow();
        r.putDouble(0, 2);
        r.putDouble(1, 3);
        r.putTimestamp(2, 20_000_000_000L);
        r.append();
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) 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(157.22760372823444, record.getDouble(0), DELTA);
        }
    }
}
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 RecordCursorFactory

use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.

the class HaversineDistDegreeGroupByFunctionFactoryTest method testOneNullAtTop.

@Test
public void testOneNullAtTop() throws SqlException {
    compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        TableWriter.Row r = w.newRow();
        r.append();
        double latDegree = 1;
        double lonDegree = 2;
        long ts = 0;
        for (int i = 0; i < 2; i++) {
            r = w.newRow();
            r.putDouble(0, latDegree);
            r.putDouble(1, lonDegree);
            r.putTimestamp(2, ts);
            r.append();
            latDegree += 1;
            lonDegree += 1;
            ts += 10_000_000_000L;
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) 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(157.22760372823444, record.getDouble(0), DELTA);
        }
    }
}
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 93 with RecordCursorFactory

use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.

the class HaversineDistDegreeGroupByFunctionFactoryTest method testOneNullsInMiddle.

@Test
public void testOneNullsInMiddle() throws SqlException {
    compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        TableWriter.Row r = w.newRow();
        r.putDouble(0, 1);
        r.putDouble(1, 2);
        r.putTimestamp(2, 10_000_000_000L);
        r.append();
        r = w.newRow();
        r.append();
        r = w.newRow();
        r.append();
        r = w.newRow();
        r.append();
        r = w.newRow();
        r.putDouble(0, 2);
        r.putDouble(1, 3);
        r.putTimestamp(2, 20_000_000_000L);
        r.append();
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) 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(157.22760372823444, record.getDouble(0), DELTA);
        }
    }
}
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 94 with RecordCursorFactory

use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.

the class HaversineDistDegreeGroupByFunctionFactoryTest method testAllNull.

@Test
public void testAllNull() throws SqlException {
    compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        for (int i = 0; i < 2; i++) {
            TableWriter.Row r = w.newRow();
            r.append();
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) 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.getDouble(0), DELTA);
        }
    }
}
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 95 with RecordCursorFactory

use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.

the class HaversineDistDegreeGroupByFunctionFactoryTest method testAggregationBySymbol.

// "select s, haversine_dist_deg(lat, lon, k) from tab",
@Test
public void testAggregationBySymbol() throws SqlException {
    compiler.compile("create table tab (s symbol, lat double, lon double, k timestamp) timestamp(k) partition by NONE", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        double latDegree = -5;
        double lonDegree = -6;
        long ts = 0;
        for (int i = 0; i < 10; i++) {
            TableWriter.Row r = w.newRow();
            r.putSym(0, "AAA");
            r.putDouble(1, latDegree);
            r.putDouble(2, lonDegree);
            r.putTimestamp(3, ts);
            r.append();
            latDegree += 1;
            lonDegree += 1;
            ts += 360000000L;
        }
        w.commit();
        latDegree = -20;
        lonDegree = 10;
        for (int i = 0; i < 10; i++) {
            TableWriter.Row r = w.newRow();
            r.putSym(0, "BBB");
            r.putDouble(1, latDegree);
            r.putDouble(2, lonDegree);
            r.putTimestamp(3, ts);
            r.append();
            latDegree += 0.1;
            lonDegree += 0.1;
            ts += 360000000L;
        }
        w.commit();
    }
    try (RecordCursorFactory factory = compiler.compile("select s, haversine_dist_deg(lat, lon, k) from tab", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(2, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals("AAA", record.getSym(0));
            Assert.assertEquals(1414.545985354098, record.getDouble(1), DELTA);
            Assert.assertTrue(cursor.hasNext());
            Assert.assertEquals("BBB", record.getSym(0));
            Assert.assertEquals(137.51028123371657, record.getDouble(1), DELTA);
        }
    }
}
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)

Aggregations

RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)136 Test (org.junit.Test)118 RecordCursor (io.questdb.cairo.sql.RecordCursor)108 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)89 Record (io.questdb.cairo.sql.Record)79 TableWriter (io.questdb.cairo.TableWriter)68 Rnd (io.questdb.std.Rnd)24 SqlCompiler (io.questdb.griffin.SqlCompiler)8 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)6 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)4 SqlException (io.questdb.griffin.SqlException)4 BaseConnection (org.postgresql.core.BaseConnection)4 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)3 Instant (de.invesdwin.util.time.Instant)3 FDate (de.invesdwin.util.time.date.FDate)3 FilesFacade (io.questdb.std.FilesFacade)3 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)3 CairoConfiguration (io.questdb.cairo.CairoConfiguration)2 CairoEngine (io.questdb.cairo.CairoEngine)2 CairoException (io.questdb.cairo.CairoException)2