Search in sources :

Example 1 with QueryCompiler

use of com.questdb.parser.sql.QueryCompiler 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 QueryCompiler

use of com.questdb.parser.sql.QueryCompiler 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 QueryCompiler

use of com.questdb.parser.sql.QueryCompiler 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 QueryCompiler

use of com.questdb.parser.sql.QueryCompiler 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 QueryCompiler

use of com.questdb.parser.sql.QueryCompiler 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

QueryCompiler (com.questdb.parser.sql.QueryCompiler)15 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)11 Test (org.junit.Test)10 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 StringSink (com.questdb.std.str.StringSink)9 RecordSource (com.questdb.ql.RecordSource)7 Factory (com.questdb.store.factory.Factory)5 LogFactory (com.questdb.log.LogFactory)2 StdoutSink (com.questdb.std.str.StdoutSink)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 ParserException (com.questdb.ex.ParserException)1 Quote (com.questdb.model.Quote)1 ParsedModel (com.questdb.parser.sql.model.ParsedModel)1 JournalException (com.questdb.std.ex.JournalException)1 ReaderFactory (com.questdb.store.factory.ReaderFactory)1 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)1