Search in sources :

Example 1 with RecordSourcePrinter

use of com.questdb.ql.RecordSourcePrinter in project questdb by bluestreak01.

the class HttpServerTest method testImportNumericHeader.

@Test
public void testImportNumericHeader() throws Exception {
    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();
    try {
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-numeric-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true&forceHeader=true", null, null));
        printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory());
        // expect first line to be treated as header
        TestUtils.assertEquals("2\n", sink);
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) ImportHandler(com.questdb.net.http.handlers.ImportHandler) StringSink(com.questdb.std.str.StringSink) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 2 with RecordSourcePrinter

use of com.questdb.ql.RecordSourcePrinter in project questdb by bluestreak01.

the class HttpServerTest method testImportUtf8.

@Test
public void testImportUtf8() throws Exception {
    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();
    try {
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import-utf8.csv", "http://localhost:9000/imp?overwrite=true&durable=true", null, null));
        printer.print(qc.compile(getFactory(), "'test-import-utf8.csv'"), getFactory());
        // expect first line to be treated as header
        TestUtils.assertEquals("авг\tавг\n", sink);
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) ImportHandler(com.questdb.net.http.handlers.ImportHandler) StringSink(com.questdb.std.str.StringSink) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 3 with RecordSourcePrinter

use of com.questdb.ql.RecordSourcePrinter in project questdb by bluestreak01.

the class HttpServerTest method testImportAppend.

@Test
public void testImportAppend() throws Exception {
    final AtomicInteger errors = new AtomicInteger();
    getFactory().setEventListener((factoryType, thread, name, event, segment, position) -> {
        if (event == FactoryEventListener.EV_UNEXPECTED_CLOSE) {
            errors.incrementAndGet();
        }
        return true;
    });
    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();
    try {
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?fmt=json", null, null));
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", null, null));
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        printer.print(qc.compile(getFactory(), "select count(StrSym), count(IntSym), count(IntCol), count(long), count() from 'test-import.csv'"), getFactory());
        TestUtils.assertEquals("252\t252\t256\t258\t258\n", sink);
    } finally {
        server.halt();
    }
    Assert.assertEquals(0, errors.get());
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerConfiguration(com.questdb.ServerConfiguration) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) ImportHandler(com.questdb.net.http.handlers.ImportHandler) StringSink(com.questdb.std.str.StringSink) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 4 with RecordSourcePrinter

use of com.questdb.ql.RecordSourcePrinter in project questdb by bluestreak01.

the class HttpServerTest method testImportWrongTypeStrictAtomicity.

@Test
public void testImportWrongTypeStrictAtomicity() throws Exception {
    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));
        }
    };
    env.dateLocaleFactory = DateLocaleFactory.INSTANCE;
    env.dateFormatFactory = DATE_FORMAT_FACTORY;
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        Assert.assertEquals(400, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp?atomicity=strict", "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}, {\"name\":\"IntCol\", \"type\":\"DATE\"}]", null));
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        RecordSource src1 = qc.compile(env.factory, "select count() from 'test-import.csv'");
        try {
            printer.print(src1, env.factory);
            TestUtils.assertEquals("0\n", sink);
        } finally {
            Misc.free(src1);
        }
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) RecordSource(com.questdb.ql.RecordSource) ServerConfiguration(com.questdb.ServerConfiguration) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) ImportHandler(com.questdb.net.http.handlers.ImportHandler) StringSink(com.questdb.std.str.StringSink) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Example 5 with RecordSourcePrinter

use of com.questdb.ql.RecordSourcePrinter in project questdb by bluestreak01.

the class HttpServerTest method testImportNoHeader.

@Test
public void testImportNoHeader() throws Exception {
    final ServerConfiguration configuration = new ServerConfiguration();
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = configuration;
    env.factory = getFactory();
    env.typeProbeCollection = TYPE_PROBE_COLLECTION;
    env.matcher = new SimpleUrlMatcher() {

        {
            put("/imp", new ImportHandler(env));
        }
    };
    HttpServer server = new HttpServer(env);
    server.start();
    try {
        StringSink sink = new StringSink();
        RecordSourcePrinter printer = new RecordSourcePrinter(sink);
        QueryCompiler qc = new QueryCompiler(env);
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-explicit-headers.csv", "http://localhost:9000/imp?name=test-import.csv&overwrite=true&durable=true", null, null));
        printer.print(qc.compile(getFactory(), "select count() from 'test-import.csv'"), getFactory());
        TestUtils.assertEquals("3\n", sink);
    } finally {
        server.halt();
    }
}
Also used : BootstrapEnv(com.questdb.BootstrapEnv) ServerConfiguration(com.questdb.ServerConfiguration) RecordSourcePrinter(com.questdb.ql.RecordSourcePrinter) ImportHandler(com.questdb.net.http.handlers.ImportHandler) StringSink(com.questdb.std.str.StringSink) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractJournalTest(com.questdb.net.ha.AbstractJournalTest) Test(org.junit.Test)

Aggregations

RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)17 StringSink (com.questdb.std.str.StringSink)14 Test (org.junit.Test)13 QueryCompiler (com.questdb.parser.sql.QueryCompiler)11 BootstrapEnv (com.questdb.BootstrapEnv)9 ServerConfiguration (com.questdb.ServerConfiguration)9 AbstractJournalTest (com.questdb.net.ha.AbstractJournalTest)9 ImportHandler (com.questdb.net.http.handlers.ImportHandler)9 RecordSource (com.questdb.ql.RecordSource)7 CountDownLatch (java.util.concurrent.CountDownLatch)5 RecordCursor (com.questdb.common.RecordCursor)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 EntryLockedException (com.questdb.cairo.pool.ex.EntryLockedException)2 EntryUnavailableException (com.questdb.cairo.pool.ex.EntryUnavailableException)2 PoolClosedException (com.questdb.cairo.pool.ex.PoolClosedException)2 ClientConfig (com.questdb.net.ha.config.ClientConfig)2 ServerConfig (com.questdb.net.ha.config.ServerConfig)2 ServerNode (com.questdb.net.ha.config.ServerNode)2 StdoutSink (com.questdb.std.str.StdoutSink)2 JournalKey (com.questdb.store.JournalKey)2