Search in sources :

Example 71 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method testCircumferenceAtEquator.

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

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method test10RowsAndNullAtEnd.

@Test
public void test10RowsAndNullAtEnd() 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 = -5;
        double lonDegree = -6;
        long ts = 0;
        TableWriter.Row r;
        for (int i = 0; i < 10; 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(1414.545985354098, 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 73 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method test10Rows.

@Test
public void test10Rows() 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 = -5;
        double lonDegree = -6;
        long ts = 0;
        for (int i = 0; i < 10; 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(1414.545985354098, 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 74 with TableWriter

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

the class HaversineDistDegreeGroupByFunctionFactoryTest method testAggregationBySymbolWithSampling.

@Test
public void testAggregationBySymbolWithSampling() throws Exception {
    compiler.compile("create table tab (s symbol, lat double, lon double, p double,  k timestamp) timestamp(k) partition by NONE", sqlExecutionContext);
    try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
        long MICROS_IN_MIN = 60_000_000L;
        // row 1
        TableWriter.Row r = w.newRow(30 * MICROS_IN_MIN);
        r.putSym(0, "AAA");
        r.putDouble(1, -5);
        r.putDouble(2, 10);
        r.putDouble(3, 1000);
        r.append();
        // row 2
        r = w.newRow(90 * MICROS_IN_MIN);
        r.putSym(0, "AAA");
        r.putDouble(1, -4);
        r.putDouble(2, 11);
        r.putDouble(3, 1000);
        r.append();
        // row 3
        r = w.newRow(100 * MICROS_IN_MIN);
        r.putSym(0, "AAA");
        r.putDouble(1, -3);
        r.putDouble(2, 12);
        r.putDouble(3, 1000);
        r.append();
        // row 4
        r = w.newRow(210 * MICROS_IN_MIN);
        r.putSym(0, "AAA");
        r.putDouble(1, -2);
        r.putDouble(2, 13);
        r.putDouble(3, 1000);
        r.append();
        // row 5
        r = w.newRow(270 * MICROS_IN_MIN);
        r.putSym(0, "AAA");
        r.putDouble(1, -1);
        r.putDouble(2, 14);
        r.putDouble(3, 1000);
        r.append();
        w.commit();
    }
    TestUtils.assertSql(compiler, sqlExecutionContext, "select k, s, haversine_dist_deg(lat, lon, k), sum(p) from tab sample by 1h fill(linear)", sink, "k\ts\thaversine_dist_deg\tsum\n" + "1970-01-01T00:30:00.000000Z\tAAA\t157.01233135733582\t1000.0\n" + "1970-01-01T01:30:00.000000Z\tAAA\t228.55327569899347\t2000.0\n" + "1970-01-01T02:30:00.000000Z\tAAA\t85.73439427824682\t1500.0\n" + "1970-01-01T03:30:00.000000Z\tAAA\t157.22760372823447\t1000.0\n" + "1970-01-01T04:30:00.000000Z\tAAA\t0.0\t1000.0\n");
}
Also used : TableWriter(io.questdb.cairo.TableWriter) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 75 with TableWriter

use of io.questdb.cairo.TableWriter 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)

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