use of io.questdb.griffin.SqlExecutionContext 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.SqlExecutionContext 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.SqlExecutionContext 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.SqlExecutionContext in project questdb by bluestreak01.
the class TableWriteBenchmark 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 test1(f long) ", sqlExecutionContext);
compiler.compile("create table if not exists test2(f timestamp) timestamp (f)", sqlExecutionContext);
compiler.compile("create table if not exists test3(f timestamp) timestamp (f) PARTITION BY DAY", sqlExecutionContext);
} catch (SqlException e) {
e.printStackTrace();
}
}
Options opt = new OptionsBuilder().include(TableWriteBenchmark.class.getSimpleName()).warmupIterations(5).measurementIterations(5).forks(1).build();
new Runner(opt).run();
LogFactory.INSTANCE.haltThread();
}
use of io.questdb.griffin.SqlExecutionContext in project questdb by bluestreak01.
the class DataFrameRecordCursorFactoryTest method testFactory.
@Test
public void testFactory() throws Exception {
TestUtils.assertMemoryLeak(() -> {
final int N = 100;
// separate two symbol columns with primitive. It will make problems apparent if index does not shift correctly
try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.STRING).col("b", ColumnType.SYMBOL).indexed(true, N / 4).col("i", ColumnType.INT).col("c", ColumnType.SYMBOL).indexed(true, N / 4).timestamp()) {
CairoTestUtils.create(model);
}
final Rnd rnd = new Rnd();
final String[] symbols = new String[N];
final int M = 1000;
final long increment = 1000000 * 60L * 4;
for (int i = 0; i < N; i++) {
symbols[i] = rnd.nextChars(8).toString();
}
rnd.reset();
// prepare the data
long timestamp = 0;
try (TableWriter writer = new TableWriter(configuration, "x")) {
for (int i = 0; i < M; i++) {
TableWriter.Row row = writer.newRow(timestamp += increment);
row.putStr(0, rnd.nextChars(20));
row.putSym(1, symbols[rnd.nextPositiveInt() % N]);
row.putInt(2, rnd.nextInt());
row.putSym(3, symbols[rnd.nextPositiveInt() % N]);
row.append();
}
writer.commit();
}
try (CairoEngine engine = new CairoEngine(configuration)) {
String value = symbols[N - 10];
int columnIndex;
int symbolKey;
RecordMetadata metadata;
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
columnIndex = reader.getMetadata().getColumnIndexQuiet("b");
symbolKey = reader.getSymbolMapReader(columnIndex).keyOf(value);
metadata = GenericRecordMetadata.copyOf(reader.getMetadata());
}
SymbolIndexRowCursorFactory symbolIndexRowCursorFactory = new SymbolIndexRowCursorFactory(columnIndex, symbolKey, true, BitmapIndexReader.DIR_FORWARD, null);
FullFwdDataFrameCursorFactory dataFrameFactory = new FullFwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION);
// entity index
final IntList columnIndexes = new IntList();
for (int i = 0, n = metadata.getColumnCount(); i < n; i++) {
columnIndexes.add(i);
}
DataFrameRecordCursorFactory factory = new DataFrameRecordCursorFactory(metadata, dataFrameFactory, symbolIndexRowCursorFactory, false, null, false, columnIndexes, null);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, null, null, -1, null);
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
while (cursor.hasNext()) {
TestUtils.assertEquals(value, record.getSym(1));
}
}
}
});
}
Aggregations