use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class TableReaderReloadBenchmark method main.
public static void main(String[] args) throws RunnerException {
try (CairoEngine engine = new CairoEngine(configuration)) {
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, null, null, -1, null);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table if not exists test(f timestamp) timestamp (f) PARTITION BY DAY", sqlExecutionContext);
} catch (SqlException e) {
throw new ExceptionInInitializerError();
}
}
Options opt = new OptionsBuilder().include(TableReaderReloadBenchmark.class.getSimpleName()).warmupIterations(2).measurementIterations(2).forks(1).build();
new Runner(opt).run();
LogFactory.INSTANCE.haltThread();
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class TelemetryTest method testTelemetryConfigUpgrade.
@Test
public void testTelemetryConfigUpgrade() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (CairoEngine engine = new CairoEngine(configuration);
SqlCompiler compiler = new SqlCompiler(engine, null);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
compiler.compile("CREATE TABLE " + TelemetryJob.configTableName + " (id long256, enabled boolean)", sqlExecutionContext);
InsertStatement ist = compiler.compile("INSERT INTO " + TelemetryJob.configTableName + " values(CAST('0x01' AS LONG256), true)", sqlExecutionContext).getInsertStatement();
InsertMethod im = ist.createMethod(sqlExecutionContext);
im.execute();
im.commit();
im.close();
ist.close();
TelemetryJob telemetryJob = new TelemetryJob(engine, null);
String expectedSql = "column type indexed indexBlockCapacity symbolCached symbolCapacity designated\n" + "id LONG256 false 0 false 0 false\n" + "enabled BOOLEAN false 0 false 0 false\n" + "version SYMBOL false 256 true 128 false\n" + "os SYMBOL false 256 true 128 false\n" + "package SYMBOL false 256 true 128 false\n";
TestUtils.assertSql(compiler, sqlExecutionContext, "SHOW COLUMNS FROM " + TelemetryJob.configTableName, sink, expectedSql);
expectedSql = "id\tversion\n" + "0x01\t\n" + "0x01\tUnknown Version\n";
TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT id, version FROM " + TelemetryJob.configTableName, sink, expectedSql);
Misc.free(telemetryJob);
}
});
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class TelemetryTest method testTelemetryUpdatesVersion.
@Test
public void testTelemetryUpdatesVersion() throws Exception {
final AtomicReference<String> refVersion = new AtomicReference<>();
BuildInformation buildInformation = new BuildInformation() {
@Override
public CharSequence getQuestDbVersion() {
return refVersion.get();
}
@Override
public CharSequence getJdkVersion() {
return null;
}
@Override
public CharSequence getCommitHash() {
return null;
}
};
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public BuildInformation getBuildInformation() {
return buildInformation;
}
};
TestUtils.assertMemoryLeak(() -> {
try (CairoEngine engine = new CairoEngine(configuration);
SqlCompiler compiler = new SqlCompiler(engine, null);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
refVersion.set("1.0");
TelemetryJob telemetryJob = new TelemetryJob(engine, null);
String os = System.getProperty(TelemetryJob.OS_NAME);
String expectedSql = "count\n1\n";
TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
expectedSql = "version\tos\n" + "1.0\t" + os + "\n";
TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT version, os FROM " + TelemetryJob.configTableName, sink, expectedSql);
Misc.free(telemetryJob);
telemetryJob = new TelemetryJob(engine, null);
expectedSql = "count\n1\n";
TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
Misc.free(telemetryJob);
refVersion.set("1.1");
telemetryJob = new TelemetryJob(engine, null);
expectedSql = "count\n2\n";
TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
expectedSql = "version\tos\n" + "1.1\t" + os + "\n";
TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT version, os FROM " + TelemetryJob.configTableName + " LIMIT -1", sink, expectedSql);
Misc.free(telemetryJob);
}
});
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class EmbeddedApiTest method testReadWrite.
@Test
public void testReadWrite() throws Exception {
final CairoConfiguration configuration = new DefaultCairoConfiguration(temp.getRoot().getAbsolutePath());
TestUtils.assertMemoryLeak(() -> {
// write part
try (final CairoEngine engine = new CairoEngine(configuration);
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
final SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table abc (a int, b byte, c short, d long, e float, g double, h date, i symbol, j string, k boolean, ts timestamp) timestamp(ts)", ctx);
try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "testing")) {
for (int i = 0; i < 10; i++) {
TableWriter.Row row = writer.newRow(Os.currentTimeMicros());
row.putInt(0, 123);
row.putByte(1, (byte) 1111);
row.putShort(2, (short) 222);
row.putLong(3, 333);
row.putFloat(4, 4.44f);
row.putDouble(5, 5.55);
row.putDate(6, System.currentTimeMillis());
row.putSym(7, "xyz");
row.putStr(8, "abc");
row.putBool(9, true);
row.append();
}
writer.commit();
}
try (RecordCursorFactory factory = compiler.compile("abc", ctx).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(ctx)) {
final Record record = cursor.getRecord();
// noinspection StatementWithEmptyBody
while (cursor.hasNext()) {
// access 'record' instance for field values
}
}
}
}
});
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class EmbeddedApiTest method testConcurrentSQLExec.
@Test
public void testConcurrentSQLExec() throws Exception {
final CairoConfiguration configuration = new DefaultCairoConfiguration(temp.getRoot().getAbsolutePath());
final Log log = LogFactory.getLog("testConcurrentSQLExec");
TestUtils.assertMemoryLeak(() -> {
WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return new int[] { -1, -1 };
}
@Override
public int getWorkerCount() {
return 2;
}
@Override
public boolean haltOnError() {
return false;
}
});
Rnd rnd = new Rnd();
try (final CairoEngine engine = new CairoEngine(configuration)) {
workerPool.assign(new GroupByJob(engine.getMessageBus()));
workerPool.start(log);
try {
// number of cores is current thread + workers in the pool
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 2);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table abc (g double, ts timestamp) timestamp(ts) partition by DAY", ctx);
long timestamp = 0;
try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "testing")) {
for (int i = 0; i < 10_000_000; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putDouble(0, rnd.nextDouble());
row.append();
timestamp += 1_000_000;
}
writer.commit();
}
try (RecordCursorFactory factory = compiler.compile("select sum(g) from abc", ctx).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(ctx)) {
final Record ignored = cursor.getRecord();
// noinspection StatementWithEmptyBody
while (cursor.hasNext()) {
// access 'record' instance for field values
}
}
}
}
} finally {
workerPool.halt();
}
}
});
}
Aggregations