use of io.questdb.griffin.SqlException in project questdb by bluestreak01.
the class MatchStrBindVariableTest method testSimple.
@Test
public void testSimple() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table x as (select rnd_str() s from long_sequence(100))", sqlExecutionContext);
try (RecordCursorFactory factory = compiler.compile("x where s ~ $1", sqlExecutionContext).getRecordCursorFactory()) {
bindVariableService.setStr(0, "GQO");
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, TestUtils.printer);
}
TestUtils.assertEquals("s\n" + "YCTGQO\n", sink);
bindVariableService.setStr(0, "QTQ");
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, TestUtils.printer);
}
TestUtils.assertEquals("s\n" + "ZWEVQTQO\n", sink);
bindVariableService.setStr(0, null);
try {
factory.getCursor(sqlExecutionContext);
Assert.fail();
} catch (SqlException e) {
Assert.assertEquals(12, e.getPosition());
TestUtils.assertContains(e.getFlyweightMessage(), "NULL regex");
}
}
});
}
use of io.questdb.griffin.SqlException 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.SqlException in project questdb by bluestreak01.
the class EqGeoHashGeoHashFunctionFactoryTest method createEqFunctionAndAssert.
private void createEqFunctionAndAssert(boolean isConstant, boolean expectedEq) {
try {
Function func = factory.newInstance(-1, args, null, null, null);
Assert.assertEquals(expectedEq, func.getBool(null));
Assert.assertEquals(isConstant, func.isConstant());
if (func instanceof NegatableBooleanFunction) {
try {
NegatingFunctionFactory nf = new NegatingFunctionFactory("noteq", factory);
func = nf.newInstance(-1, args, null, null, null);
Assert.assertEquals(!expectedEq, func.getBool(null));
} catch (SqlException e) {
e.printStackTrace();
Assert.fail();
}
}
} catch (SqlException e) {
Assert.fail(e.getMessage());
}
}
use of io.questdb.griffin.SqlException 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.SqlException in project questdb by bluestreak01.
the class SampleByTest method testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable.
@Test
public void testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable() 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, 300000000) k" + " from" + " long_sequence(100)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
RecordCursorFactory factory = compiler.compile("select k, count() from x sample by 90m align to calendar time zone $1 with offset $2", sqlExecutionContext).getRecordCursorFactory();
String expectedMoscow = "k\tcount\n" + "1970-01-02T22:45:00.000000Z\t3\n" + "1970-01-03T00:15:00.000000Z\t18\n" + "1970-01-03T01:45:00.000000Z\t18\n" + "1970-01-03T03:15:00.000000Z\t18\n" + "1970-01-03T04:45:00.000000Z\t18\n" + "1970-01-03T06:15:00.000000Z\t18\n" + "1970-01-03T07:45:00.000000Z\t7\n";
String expectedPrague = "k\tcount\n" + "1970-01-02T23:10:00.000000Z\t8\n" + "1970-01-03T00:40:00.000000Z\t18\n" + "1970-01-03T02:10:00.000000Z\t18\n" + "1970-01-03T03:40:00.000000Z\t18\n" + "1970-01-03T05:10:00.000000Z\t18\n" + "1970-01-03T06:40:00.000000Z\t18\n" + "1970-01-03T08:10:00.000000Z\t2\n";
sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Moscow");
sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
assertCursor(expectedMoscow, cursor, factory.getMetadata(), true);
}
// invalid timezone
sqlExecutionContext.getBindVariableService().setStr(0, "Oopsie");
sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
try {
factory.getCursor(sqlExecutionContext);
Assert.fail();
} catch (SqlException e) {
Assert.assertEquals(67, e.getPosition());
TestUtils.assertContains(e.getFlyweightMessage(), "invalid timezone: Oopsie");
}
sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
sqlExecutionContext.getBindVariableService().setStr(1, "uggs");
try {
factory.getCursor(sqlExecutionContext);
Assert.fail();
} catch (SqlException e) {
Assert.assertEquals(82, e.getPosition());
TestUtils.assertContains(e.getFlyweightMessage(), "invalid offset: uggs");
}
sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
sqlExecutionContext.getBindVariableService().setStr(1, "00:10");
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
assertCursor(expectedPrague, cursor, factory.getMetadata(), true);
}
});
}
Aggregations