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();
}
}
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();
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations