use of io.questdb.griffin.SqlCompiler 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.SqlCompiler in project questdb by bluestreak01.
the class SampleByTest method testSampleFillLinearConstructorFail.
@Test
public void testSampleFillLinearConstructorFail() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 3600000000) k" + " from" + " long_sequence(20000000)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
FilesFacade ff = new FilesFacadeImpl() {
int count = 4;
@Override
public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
if (count-- > 0) {
return super.mmap(fd, len, offset, flags, memoryTag);
}
return -1;
}
};
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
try (CairoEngine engine = new CairoEngine(configuration)) {
try (SqlCompiler compiler = new SqlCompiler(engine)) {
try {
compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext);
Assert.fail();
} catch (SqlException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "could not mmap"));
}
Assert.assertEquals(0, engine.getBusyReaderCount());
Assert.assertEquals(0, engine.getBusyWriterCount());
}
}
});
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class SampleByTest method testSampleFillLinearFail.
@Test
public void testSampleFillLinearFail() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 3600000000) k" + " from" + " long_sequence(20000000)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
FilesFacade ff = new FilesFacadeImpl() {
int count = 10;
@Override
public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
if (count-- > 0) {
return super.mmap(fd, len, offset, flags, memoryTag);
}
return -1;
}
};
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
try (CairoEngine engine = new CairoEngine(configuration)) {
try (SqlCompiler compiler = new SqlCompiler(engine)) {
try {
try (RecordCursorFactory factory = compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext).getRecordCursorFactory()) {
// with mmap count = 5 we should get failure in cursor
factory.getCursor(sqlExecutionContext);
}
Assert.fail();
} catch (CairoException e) {
Assert.assertTrue(Chars.contains(e.getMessage(), "could not mmap"));
}
Assert.assertEquals(0, engine.getBusyReaderCount());
Assert.assertEquals(0, engine.getBusyWriterCount());
}
}
});
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class SampleByTest method testGroupByFail.
@Test
public void testGroupByFail() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as " + "(" + "select" + " x," + " rnd_double(0) d," + " rnd_symbol('XY','ZP', null, 'UU') c" + " from" + " long_sequence(1000000)" + ")", sqlExecutionContext);
engine.clear();
final FilesFacade ff = new FilesFacadeImpl() {
int count = 10;
@Override
public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
if (count-- > 0) {
return super.mmap(fd, len, offset, flags, memoryTag);
}
return -1;
}
};
final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public FilesFacade getFilesFacade() {
return ff;
}
};
try (CairoEngine engine = new CairoEngine(configuration)) {
try (SqlCompiler compiler = new SqlCompiler(engine)) {
try {
try (RecordCursorFactory factory = compiler.compile("select c, sum_t(d) from x", sqlExecutionContext).getRecordCursorFactory()) {
factory.getCursor(sqlExecutionContext);
}
Assert.fail();
} catch (CairoException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "could not mmap");
}
Assert.assertEquals(0, engine.getBusyReaderCount());
Assert.assertEquals(0, engine.getBusyWriterCount());
}
engine.clear();
}
});
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class TextLoaderTest method assertTimestampAsLong.
private void assertTimestampAsLong(String nominatedTimestamp, String expectedMeta) throws Exception {
final TextConfiguration textConfiguration = new DefaultTextConfiguration() {
@Override
public int getTextAnalysisMaxLines() {
return 3;
}
};
CairoConfiguration configuration = new DefaultCairoConfiguration(root) {
@Override
public TextConfiguration getTextConfiguration() {
return textConfiguration;
}
};
try (CairoEngine engine = new CairoEngine(configuration)) {
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table test(StrSym symbol, ts timestamp) " + nominatedTimestamp, sqlExecutionContext);
engine.releaseAllWriters();
}
assertNoLeak(engine, textLoader -> {
String expected = "StrSym\tts\n" + "CMP1\t1970-04-26T17:46:40.000000Z\n" + "CMP2\t1970-04-26T17:46:40.000001Z\n" + "CMP1\t1970-04-26T17:46:40.000002Z\n" + "CMP2\t1970-04-26T17:46:40.000003Z\n" + "CMP1\t1970-04-26T17:46:40.000004Z\n";
String csv = "StrSym,ts\n" + "CMP1,10000000000000\n" + "CMP2,10000000000001\n" + "CMP1,10000000000002\n" + "CMP2,10000000000003\n" + "CMP1,10000000000004\n";
configureLoaderDefaults(textLoader, (byte) ',');
textLoader.setForceHeaders(false);
playText(engine, textLoader, csv, 1024, expected, expectedMeta, 5, 5);
});
}
}
Aggregations