Search in sources :

Example 21 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method test2DistancesAtEquator.

@Test
public void test2DistancesAtEquator() throws SqlException {
    compiler.compile("create table tab1 (lat double, lon double, k timestamp)", sqlExecutionContext);
    compiler.compile("create table tab2 (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab1", "testing")) {
        double lonDegree = 0;
        long ts = 0;
        for (int i = 0; i < 10; i++) {
            TableWriter.Row r = w.newRow();
            r.putDouble(0, 0);
            r.putDouble(1, lonDegree);
            r.putTimestamp(2, ts);
            r.append();
            lonDegree += 1;
            ts += 10_000_000_000L;
        }
        w.commit();
    }
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab2", "testing")) {
        double lonDegree = -180;
        long ts = 0;
        for (int i = 0; i < 10; i++) {
            TableWriter.Row r = w.newRow();
            r.putDouble(0, 0);
            r.putDouble(1, lonDegree);
            r.putTimestamp(2, ts);
            r.append();
            lonDegree += 1;
            ts += 10_000_000_000L;
        }
        w.commit();
    }
    double distance1;
    try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) from tab1", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            distance1 = record.getDouble(0);
        }
    }
    double distance2;
    try (RecordCursorFactory factory = compiler.compile("select haversine_dist_deg(lat, lon, k) from tab2", sqlExecutionContext).getRecordCursorFactory()) {
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            Record record = cursor.getRecord();
            Assert.assertEquals(1, cursor.size());
            Assert.assertTrue(cursor.hasNext());
            distance2 = record.getDouble(0);
        }
    }
    Assert.assertEquals(distance1, distance2, 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 22 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method test3Rows.

@Test
public void test3Rows() throws SqlException {
    compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        double latDegree = 1;
        double lonDegree = 2;
        long ts = 0;
        for (int i = 0; i < 3; i++) {
            TableWriter.Row 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(314.4073265716869, 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 23 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method testPositiveLatLon.

@Test
public void testPositiveLatLon() throws SqlException {
    compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        double latDegree = 1;
        double lonDegree = 2;
        long ts = 0;
        for (int i = 0; i < 2; i++) {
            TableWriter.Row 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 24 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method testOneNullAtEnd.

@Test
public void testOneNullAtEnd() 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;
        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;
        }
        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(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 25 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method testNegativeLatLon.

@Test
public void testNegativeLatLon() throws SqlException {
    compiler.compile("create table tab (lat double, lon double, k timestamp)", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        double latDegree = -1;
        double lonDegree = -2;
        long ts = 0;
        for (int i = 0; i < 2; i++) {
            TableWriter.Row r = w.newRow();
            r.putDouble(0, latDegree);
            r.putDouble(1, lonDegree);
            r.putTimestamp(2, ts);
            r.append();
            latDegree -= 1;
            lonDegree -= 1;
        }
        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)

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