Search in sources :

Example 36 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class HttpServerTest method testImportIntoBusyJournal2.

@Test
public void testImportIntoBusyJournal2() throws Exception {
    WriterFactory f = getFactory();
    try (JournalWriter w = f.writer(new JournalStructure("small.csv").$int("X").$int("Y").$())) {
        JournalEntryWriter ew = w.entryWriter();
        ew.putInt(0, 3);
        ew.putInt(1, 30);
        ew.append();
        w.commit();
        BootstrapEnv env = new BootstrapEnv();
        env.configuration = new ServerConfiguration();
        env.factory = getFactory();
        env.typeProbeCollection = TYPE_PROBE_COLLECTION;
        env.matcher = new SimpleUrlMatcher() {

            {
                put("/imp", new ImportHandler(env));
            }
        };
        HttpServer server = new HttpServer(env);
        server.start();
        StringBuilder response = new StringBuilder();
        try {
            Assert.assertEquals(200, HttpTestUtils.upload("/csv/small.csv", "http://localhost:9000/imp?fmt=json", null, response));
            Assert.assertTrue(Chars.startsWith(response, "{\"status\":\"com.questdb.ex.WriterBusyException\"}"));
        } catch (IOException e) {
            Assert.assertTrue(e.getMessage().contains("Connection reset"));
        } finally {
            server.halt();
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) BootstrapEnv(com.questdb.BootstrapEnv) WriterFactory(com.questdb.store.factory.WriterFactory) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) ServerConfiguration(com.questdb.ServerConfiguration) ImportHandler(com.questdb.net.http.handlers.ImportHandler) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 37 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class QueryHandlerTest method generateJournal.

private static void generateJournal(String name, QueryResponse.Tab[] recs, int count) throws JournalException, NumericException {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure(name).$sym("id").$double("x").$double("y").$long("z").$int("w").$ts())) {
        Rnd rnd = new Rnd();
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < count; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putSym(0, recs.length > i ? recs[i].id : "id" + i);
            ew.putDouble(1, recs.length > i ? recs[i].x : rnd.nextDouble());
            if (recs.length > i) {
                ew.putDouble(2, recs[i].y);
                ew.putLong(3, recs[i].z);
            } else {
                if (rnd.nextPositiveInt() % 10 == 0) {
                    ew.putNull(2);
                } else {
                    ew.putDouble(2, rnd.nextDouble());
                }
                if (rnd.nextPositiveInt() % 10 == 0) {
                    ew.putNull(3);
                } else {
                    ew.putLong(3, rnd.nextLong() % 500);
                }
            }
            ew.putInt(4, recs.length > i ? recs[i].w : rnd.nextInt() % 500);
            ew.putDate(5, recs.length > i ? recs[i].timestamp.getTime() : t);
            t += 10;
            ew.append();
        }
        w.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Example 38 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class AggregationTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    int recordCount = 10000;
    int employeeCount = 10;
    try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders").$int("orderId").$int("customerId").$int("productId").$str("employeeId").$ts("orderDate").$int("quantity").$double("price").$float("rate").recordCountHint(recordCount).$())) {
        Rnd rnd = new Rnd();
        String[] employees = new String[employeeCount];
        for (int i = 0; i < employees.length; i++) {
            employees[i] = rnd.nextString(9);
        }
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        int orderId = 0;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = orders.entryWriter();
            w.putInt(0, ++orderId);
            w.putInt(1, rnd.nextPositiveInt() % 500);
            w.putInt(2, rnd.nextPositiveInt() % 200);
            w.putStr(3, employees[rnd.nextPositiveInt() % employeeCount]);
            w.putDate(4, timestamp += tsIncrement);
            w.putInt(5, rnd.nextPositiveInt());
            w.putDouble(6, rnd.nextDouble());
            w.putFloat(7, rnd.nextFloat());
            w.append();
        }
        orders.commit();
    }
    try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("stars").$int("galaxy").$int("star").$double("diameter").$())) {
        Rnd rnd = new Rnd();
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement);
            w.putInt(0, rnd.nextPositiveInt() % 10);
            w.putInt(1, rnd.nextPositiveInt());
            int dividend = (rnd.nextPositiveInt() % 10);
            w.putDouble(2, Double.MAX_VALUE / (double) (dividend == 0 ? 1 : dividend));
            w.append();
        }
        stars.commit();
    }
    try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("stars2").$int("galaxy").$int("star").$double("diameter").$())) {
        Rnd rnd = new Rnd();
        double r = Math.sqrt(Double.MAX_VALUE);
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement);
            w.putInt(0, rnd.nextPositiveInt() % 10);
            w.putInt(1, rnd.nextPositiveInt());
            int dividend = (rnd.nextPositiveInt() % 10);
            w.putDouble(2, r / (double) (dividend == 0 ? 1 : dividend));
            w.append();
        }
        stars.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

Example 39 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class NullAggregationTest method createTabWithNaNs2.

private static void createTabWithNaNs2() throws JournalException, NumericException {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("tab").$str("id").$double("x").$double("y").$long("z").$int("w").$str("a").$ts())) {
        Rnd rnd = new Rnd();
        int n = 128;
        ObjHashSet<String> names = getNames(rnd, n);
        int mask = n - 1;
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < 10000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putStr(0, names.get(rnd.nextInt() & mask));
            ew.putDouble(1, rnd.nextDouble());
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(2);
            } else {
                ew.putDouble(2, rnd.nextDouble());
            }
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(3);
            } else {
                ew.putLong(3, rnd.nextLong() % 500);
            }
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(4);
            } else {
                ew.putInt(4, rnd.nextInt() % 500);
            }
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(5);
            } else {
                ew.putStr(5, names.get(rnd.nextInt() & mask));
            }
            ew.putDate(6, t += (60 * 60 * 1000));
            ew.append();
        }
        w.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Example 40 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class NullCountingTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    int recordCount = 10000;
    int productCount = 200;
    int employeeCount = 10;
    try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders").$int("orderId").$int("customerId").$str("productId").$sym("employeeId").$ts("orderDate").$int("quantity").$double("price").$float("rate").$long("x").recordCountHint(recordCount).$())) {
        Rnd rnd = new Rnd();
        String[] employees = new String[employeeCount];
        for (int i = 0; i < employees.length; i++) {
            if (rnd.nextPositiveInt() % 10 == 0) {
                employees[i] = null;
            } else {
                employees[i] = rnd.nextString(9);
            }
        }
        String[] productId = new String[productCount];
        for (int i = 0; i < productId.length; i++) {
            if (rnd.nextPositiveInt() % 30 == 0) {
                productId[i] = null;
            } else {
                productId[i] = rnd.nextString(9);
            }
        }
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        int orderId = 0;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = orders.entryWriter();
            w.putInt(0, ++orderId);
            w.putInt(1, rnd.nextPositiveInt() % 500);
            w.putStr(2, productId[rnd.nextPositiveInt() % productCount]);
            w.putSym(3, employees[rnd.nextPositiveInt() % employeeCount]);
            w.putDate(4, timestamp += tsIncrement);
            w.putInt(5, rnd.nextPositiveInt() % 10 == 0 ? Numbers.INT_NaN : rnd.nextPositiveInt());
            w.putDouble(6, rnd.nextPositiveInt() % 10 == 0 ? Double.NaN : rnd.nextDouble());
            w.putFloat(7, rnd.nextPositiveInt() % 10 == 0 ? Float.NaN : rnd.nextFloat());
            w.putLong(8, rnd.nextPositiveInt() % 10 == 0 ? Numbers.LONG_NaN : rnd.nextLong());
            w.append();
        }
        orders.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

Aggregations

JournalEntryWriter (com.questdb.store.JournalEntryWriter)67 JournalWriter (com.questdb.store.JournalWriter)59 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)47 Rnd (com.questdb.std.Rnd)43 Test (org.junit.Test)31 AbstractTest (com.questdb.test.tools.AbstractTest)28 BeforeClass (org.junit.BeforeClass)10 RecordCursor (com.questdb.common.RecordCursor)5 Record (com.questdb.common.Record)4 RecordSource (com.questdb.ql.RecordSource)4 StringSink (com.questdb.std.str.StringSink)4 BootstrapEnv (com.questdb.BootstrapEnv)3 ServerConfiguration (com.questdb.ServerConfiguration)3 ObjHashSet (com.questdb.std.ObjHashSet)3 Factory (com.questdb.store.factory.Factory)3 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)2 DoubleRecordSourceColumn (com.questdb.ql.ops.col.DoubleRecordSourceColumn)2 DoubleConstant (com.questdb.ql.ops.constant.DoubleConstant)2 AddDoubleOperator (com.questdb.ql.ops.plus.AddDoubleOperator)2 VirtualColumnRecordSource (com.questdb.ql.virtual.VirtualColumnRecordSource)2