Search in sources :

Example 1 with RecordSource

use of com.questdb.ql.RecordSource 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 2 with RecordSource

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

the class HttpServerTest method testImportWrongType.

@Test
public void testImportWrongType() throws Exception {
    BootstrapEnv env = new BootstrapEnv();
    env.configuration = new ServerConfiguration();
    env.factory = getFactory();
    env.typeProbeCollection = TYPE_PROBE_COLLECTION;
    env.dateLocaleFactory = DateLocaleFactory.INSTANCE;
    env.dateFormatFactory = DATE_FORMAT_FACTORY;
    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", "[{\"name\":\"IsoDate\", \"type\":\"DATE\"}, {\"name\":\"IntCol\", \"type\":\"DOUBLE\"}]", null));
        Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import.csv", "http://localhost:9000/imp", "[{\"name\":\"IsoDate\", \"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(StrSym), count(IntSym), count(IntCol), count(long), count() from 'test-import.csv'");
        try {
            printer.print(src1, env.factory);
            TestUtils.assertEquals("252\t252\t256\t258\t258\n", sink);
        } finally {
            Misc.free(src1);
        }
        RecordSource src2 = qc.compile(env.factory, "'test-import.csv'");
        try {
            Assert.assertEquals(ColumnType.DOUBLE, src2.getMetadata().getColumn("IntCol").getType());
        } finally {
            Misc.free(src2);
        }
    } 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 3 with RecordSource

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

the class PlainTextLexerTest method testImport.

@Test
public void testImport() throws Exception {
    String file = this.getClass().getResource("/csv/test-import.csv").getFile();
    ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, null, false);
    String location = "test-import.csv";
    Assert.assertEquals(JournalConfiguration.EXISTS, getFactory().getConfiguration().exists(location));
    try (Journal r = getFactory().reader(location)) {
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(10, m.getColumnCount());
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(0).type);
        Assert.assertEquals(ColumnType.INT, m.getColumnQuick(1).type);
        Assert.assertEquals(ColumnType.INT, m.getColumnQuick(2).type);
        Assert.assertEquals(ColumnType.DOUBLE, m.getColumnQuick(3).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(4).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(5).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(6).type);
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(7).type);
        Assert.assertEquals(ColumnType.BOOLEAN, m.getColumnQuick(8).type);
        Assert.assertEquals(ColumnType.LONG, m.getColumnQuick(9).type);
    }
    File actual = new File(getFactory().getConfiguration().getJournalBase(), "exp.csv");
    File expected = new File(this.getClass().getResource("/csv/test-export-expected.csv").getFile());
    try (RecordSource rs = compile("'" + location + "'")) {
        ExportManager.export(rs, getFactory(), actual, PlainTextDelimiter.CSV);
        TestUtils.assertEquals(expected, actual);
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) RecordSource(com.questdb.ql.RecordSource) Journal(com.questdb.store.Journal) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 4 with RecordSource

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

the class PlainTextLexerTest method testImportMalformedQuote.

@Test
public void testImportMalformedQuote() throws Exception {
    String file = this.getClass().getResource("/csv/test-import-malformed.csv").getFile();
    ImportManager.importFile(getFactory(), file, PlainTextDelimiter.CSV, null, false);
    String location = "test-import-malformed.csv";
    Assert.assertEquals(JournalConfiguration.EXISTS, factoryContainer.getConfiguration().exists(location));
    try (Journal r = getFactory().reader(location)) {
        JournalMetadata m = r.getMetadata();
        Assert.assertEquals(10, m.getColumnCount());
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(0).type);
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(1).type);
        Assert.assertEquals(ColumnType.INT, m.getColumnQuick(2).type);
        Assert.assertEquals(ColumnType.DOUBLE, m.getColumnQuick(3).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(4).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(5).type);
        Assert.assertEquals(ColumnType.DATE, m.getColumnQuick(6).type);
        Assert.assertEquals(ColumnType.STRING, m.getColumnQuick(7).type);
        Assert.assertEquals(ColumnType.BOOLEAN, m.getColumnQuick(8).type);
        Assert.assertEquals(ColumnType.LONG, m.getColumnQuick(9).type);
    }
    File actual = new File(factoryContainer.getConfiguration().getJournalBase(), "exp.csv");
    File expected = new File(this.getClass().getResource("/csv/test-import-malformed-expected.csv").getFile());
    try (RecordSource rs = compile("'" + location + "'")) {
        ExportManager.export(rs, getFactory(), actual, PlainTextDelimiter.CSV);
        TestUtils.assertEquals(expected, actual);
    }
}
Also used : JournalMetadata(com.questdb.store.factory.configuration.JournalMetadata) RecordSource(com.questdb.ql.RecordSource) Journal(com.questdb.store.Journal) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 5 with RecordSource

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

the class AbstractOptimiserTest method assertPlan2.

protected void assertPlan2(CharSequence expected, CharSequence query) throws ParserException {
    sink.clear();
    try (RecordSource recordSource = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
        recordSource.toSink(sink);
        String s = gson.toJson(jp.parse(sink.toString()));
        TestUtils.assertEquals(expected, s);
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource)

Aggregations

RecordSource (com.questdb.ql.RecordSource)30 Test (org.junit.Test)18 AbstractTest (com.questdb.test.tools.AbstractTest)12 RecordCursor (com.questdb.common.RecordCursor)11 Record (com.questdb.common.Record)10 QueryCompiler (com.questdb.parser.sql.QueryCompiler)7 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)7 StringSink (com.questdb.std.str.StringSink)5 JournalWriter (com.questdb.store.JournalWriter)5 JournalEntryWriter (com.questdb.store.JournalEntryWriter)4 Factory (com.questdb.store.factory.Factory)4 BootstrapEnv (com.questdb.BootstrapEnv)3 ServerConfiguration (com.questdb.ServerConfiguration)3 Quote (com.questdb.model.Quote)3 AbstractJournalTest (com.questdb.net.ha.AbstractJournalTest)3 ImportHandler (com.questdb.net.http.handlers.ImportHandler)3 File (java.io.File)3 SymbolTable (com.questdb.common.SymbolTable)2 ClientConfig (com.questdb.net.ha.config.ClientConfig)2 ServerConfig (com.questdb.net.ha.config.ServerConfig)2