use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class TruncateTest method testTruncateOpenReader.
@Test
public void testTruncateOpenReader() throws Exception {
assertMemoryLeak(() -> {
createX(1_000_000);
assertQuery("count\n" + "1000000\n", "select count() from x", null, false, true);
try (RecordCursorFactory factory = compiler.compile("select * from x", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
record.getInt(0);
record.getSym(1);
record.getDouble(2);
}
}
}
compiler.compile("truncate table 'x'", sqlExecutionContext);
});
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class TruncateTest method testDropTableWithCachedPlan.
private void testDropTableWithCachedPlan(String query) throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table y as (" + "select timestamp_sequence(0, 1000000000) timestamp," + " rnd_symbol('a','b',null) symbol1 " + " from long_sequence(10)" + ") timestamp (timestamp)", sqlExecutionContext);
try (RecordCursorFactory factory = compiler.compile(query, sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
sink.clear();
TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
}
compiler.compile("drop table y", sqlExecutionContext);
compiler.compile("create table y as ( " + " select " + " timestamp_sequence('1970-01-01T02:30:00.000000Z', 1000000000L) timestamp " + " ,rnd_str('a','b','c', 'd', 'e', 'f',null) symbol2" + " ,rnd_str('a','b',null) symbol1" + " from long_sequence(10)" + ")", sqlExecutionContext);
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
Assert.fail();
} catch (ReaderOutOfDateException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "cannot be used because table schema has changed [table='y']");
}
}
});
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class UnionTest method testExceptOfLiterals.
@Test
public void testExceptOfLiterals() throws Exception {
assertMemoryLeak(() -> {
final String expected1 = "2020-04-21\t1\n" + "2020-04-21\t1\n";
final String query1 = "select '2020-04-21', 1\n" + "except\n" + "select '2020-04-22', 2";
try (RecordCursorFactory rcf = compiler.compile(query1, sqlExecutionContext).getRecordCursorFactory()) {
assertCursor(expected1, rcf, true, false, false);
}
final String expected2 = "a\tb\n" + "2020-04-21\t1\n";
final String query2 = "select '2020-04-21' a, 1 b\n" + "except\n" + "select '2020-04-22', 2";
try (RecordCursorFactory rcf = compiler.compile(query2, sqlExecutionContext).getRecordCursorFactory()) {
assertCursor(expected2, rcf, true, false, false);
}
});
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class UnionTest method testIntersectOfLiterals.
@Test
public void testIntersectOfLiterals() throws Exception {
assertMemoryLeak(() -> {
final String expected1 = "2020-04-21\t1\n" + "2020-04-21\t1\n";
final String query1 = "select '2020-04-21', 1\n" + "intersect\n" + "select '2020-04-21', 1";
try (RecordCursorFactory rcf = compiler.compile(query1, sqlExecutionContext).getRecordCursorFactory()) {
assertCursor(expected1, rcf, true, false, false);
}
final String expected2 = "a\tb\n" + "2020-04-21\t1\n";
final String query2 = "select '2020-04-21' a, 1 b\n" + "intersect\n" + "select '2020-04-21', 1";
try (RecordCursorFactory rcf = compiler.compile(query2, sqlExecutionContext).getRecordCursorFactory()) {
assertCursor(expected2, rcf, true, false, false);
}
});
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class UnionTest method testUnionAllOfSymbol.
// select distinct sym from a union all b
@Test
public void testUnionAllOfSymbol() throws Exception {
assertMemoryLeak(() -> {
final String expected = "t\n" + "CAR\n" + "CAR\n" + "VAN\n" + "PLANE\n" + "PLANE\n" + "PLANE\n" + "PLANE\n";
final String expected2 = "t\n" + "CAR\n" + "VAN\n" + "PLANE\n" + "BICYCLE\n" + "SCOOTER\n";
compiler.compile("CREATE TABLE x as " + "(SELECT " + " rnd_symbol('CAR', 'VAN', 'PLANE') t " + " FROM long_sequence(7) x)" + " partition by NONE", sqlExecutionContext);
try (RecordCursorFactory rcf = compiler.compile("x", sqlExecutionContext).getRecordCursorFactory()) {
assertCursor(expected, rcf, true, true, true);
}
SharedRandom.RANDOM.get().reset();
compiler.compile("CREATE TABLE y as " + "(SELECT " + " rnd_symbol('PLANE', 'BICYCLE', 'SCOOTER') t " + " FROM long_sequence(7) x)" + " partition by NONE", sqlExecutionContext);
try (RecordCursorFactory factory = compiler.compile("select distinct t from x union all y", sqlExecutionContext).getRecordCursorFactory()) {
assertCursor(expected2, factory, false, true, false);
}
});
}
Aggregations