use of com.questdb.parser.sql.QueryCompiler in project questdb by bluestreak01.
the class SQLExportToTextFile method main.
public static void main(String[] args) throws JournalException, IOException, ParserException {
if (args.length < 1) {
System.out.println("Usage: SQLExportToTextFile <path>");
System.exit(1);
}
try (Factory factory = new Factory(args[0], 1000, 1, 0)) {
// import movies data to query
ImportManager.importFile(factory, SQLExamples.class.getResource("/movies.csv").getFile(), ',', null, false);
// Create SQL engine instance.
QueryCompiler compiler = new QueryCompiler();
try (RecordSource rs = compiler.compile(factory, "select year, count() count from (select title, match('\\(([0-9]*?)\\)', title) year from 'movies.csv' order by year desc)")) {
ExportManager.export(rs, factory, new File(args[0], "export.csv"), ',');
}
}
}
use of com.questdb.parser.sql.QueryCompiler in project questdb by bluestreak01.
the class SQLParameters method main.
public static void main(String[] args) throws JournalException, ParserException, IOException {
if (args.length < 1) {
System.out.println("Usage: SQLParameters <path>");
System.exit(1);
}
JournalConfiguration configuration = new JournalConfigurationBuilder().build(args[0]);
try (Factory factory = new Factory(configuration, 1000, 1, 0)) {
// import movies data to query
ImportManager.importFile(factory, SQLParameters.class.getResource("/movies.csv").getFile(), ',', null, false);
// Create SQL engine instance.
QueryCompiler compiler = new QueryCompiler();
try (RecordSource rs = compiler.compile(factory, "'movies.csv' where movieId = :id")) {
RecordSourcePrinter printer = new RecordSourcePrinter(new StdoutSink());
// use of parameters avoids expensive query compilation
rs.getParam(":id").set(62198);
printer.print(rs, factory);
System.out.println("----------------");
rs.getParam(":id").set(125);
printer.print(rs, factory);
}
}
}
use of com.questdb.parser.sql.QueryCompiler in project questdb by bluestreak01.
the class PerformanceTest method testAllBySymbolValueOverIntervalNew.
@SuppressWarnings("StatementWithEmptyBody")
@Test
public void testAllBySymbolValueOverIntervalNew() throws JournalException, ParserException, NumericException {
try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "quote", TEST_DATA_SIZE)) {
TestUtils.generateQuoteData(w, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
w.commit();
}
QueryCompiler compiler = new QueryCompiler();
Factory factory = getFactory();
try (RecordSource src = compiler.compile(factory, "quote where timestamp = '2013-10-05T10:00:00.000Z;10d' and sym = 'LLOY.L'")) {
int count = 1000;
long t = 0;
for (int i = -count; i < count; i++) {
if (i == 0) {
t = System.nanoTime();
}
RecordCursor c = src.prepareCursor(factory);
try {
for (; c.hasNext(); ) {
c.next();
}
} finally {
c.releaseCursor();
}
}
LOG.info().$("NEW journal.query().all().withKeys(\"LLOY.L\").slice(interval) (query only) latency: ").$((System.nanoTime() - t) / count / 1000).$("μs").$();
}
}
use of com.questdb.parser.sql.QueryCompiler in project questdb by bluestreak01.
the class HttpServerTest method testImportNumberPrefixedColumn.
@Test
public void testImportNumberPrefixedColumn() 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 {
Assert.assertEquals(200, HttpTestUtils.upload("/csv/test-import-num-prefix.csv", "http://localhost:9000/imp?fmt=json", null, null));
StringSink sink = new StringSink();
RecordSourcePrinter printer = new RecordSourcePrinter(sink);
QueryCompiler qc = new QueryCompiler(env);
try (RecordSource rs = qc.compile(env.factory, "select count(StrSym), count(IntSym), count(_1IntCol), count(long), count() from 'test-import-num-prefix.csv'")) {
printer.print(rs, env.factory);
}
TestUtils.assertEquals("126\t126\t128\t129\t129\n", sink);
} finally {
server.halt();
}
}
use of com.questdb.parser.sql.QueryCompiler in project questdb by bluestreak01.
the class SQLErrorHandling method main.
public static void main(String[] args) throws JournalException, ParserException, IOException {
if (args.length < 1) {
System.out.println("Usage: SQLErrorHandling <path>");
System.exit(1);
}
try (Factory factory = new Factory(args[0], 1000, 1, 0)) {
// import movies data to query
ImportManager.importFile(factory, SQLErrorHandling.class.getResource("/movies.csv").getFile(), ',', null, false);
// Create SQL engine instance.
QueryCompiler compiler = new QueryCompiler();
try {
// in case of exception all allocated resources are freed automatically
compiler.compile(factory, "'movies.csv' where movieIds = :id");
} catch (ParserException e) {
LOG.error().$("At (").$(QueryError.getPosition()).$(") : ").$(QueryError.getMessage()).$();
}
}
}
Aggregations