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