use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class JoinTest method testCrossTripleOverflow.
@Test
public void testCrossTripleOverflow() throws Exception {
assertMemoryLeak(() -> {
final CompiledQuery cq = compiler.compile("select * from long_sequence(1000000000) a cross join long_sequence(1000000000) b cross join long_sequence(1000000000) c", sqlExecutionContext);
final RecordCursorFactory factory = cq.getRecordCursorFactory();
try {
Assert.assertNotNull(factory);
sink.clear();
printer.printHeader(factory.getMetadata(), sink);
TestUtils.assertEquals("x\tx1\tx2\n", sink);
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Assert.assertEquals(Long.MAX_VALUE, cursor.size());
}
} finally {
Misc.free(factory);
}
});
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class LatestByParallelTest method assertQuery.
private static void assertQuery(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, String expected, String ddl, String query) throws SqlException {
compiler.compile(ddl, sqlExecutionContext);
CompiledQuery cc = compiler.compile(query, sqlExecutionContext);
RecordCursorFactory factory = cc.getRecordCursorFactory();
try {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
TestUtils.assertCursor(expected, cursor, factory.getMetadata(), true, sink);
}
} finally {
Misc.free(factory);
}
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class MemoryLeakTest method testQuestDbForLeaks.
@Test
public void testQuestDbForLeaks() throws Exception {
assertMemoryLeak(() -> {
int N = 1_000_000;
populateUsersTable(engine, N);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
final BindVariableService bindVariableService = new BindVariableServiceImpl(configuration);
bindVariableService.setLong("low", 0L);
bindVariableService.setLong("high", 0L);
try (final SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, bindVariableService, null)) {
StringSink sink = new StringSink();
sink.clear();
sink.put("users");
sink.put(" latest by id where sequence > :low and sequence < :high");
try (RecordCursorFactory rcf = compiler.compile(sink, executionContext).getRecordCursorFactory()) {
bindVariableService.setLong("low", 0);
bindVariableService.setLong("high", N + 1);
Misc.free(rcf.getCursor(executionContext));
}
}
} finally {
Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
engine.clear();
Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
}
});
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class O3CommitLagTest method insertUncommitted.
private void insertUncommitted(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, String sql, TableWriter writer) throws SqlException {
minTimestamp = Long.MAX_VALUE;
maxTimestamp = Long.MIN_VALUE;
try (RecordCursorFactory factory = compiler.compile(sql, sqlExecutionContext).getRecordCursorFactory()) {
RecordMetadata metadata = factory.getMetadata();
int timestampIndex = writer.getMetadata().getTimestampIndex();
EntityColumnFilter toColumnFilter = new EntityColumnFilter();
toColumnFilter.of(metadata.getColumnCount());
if (null == copier) {
copier = SqlCompiler.assembleRecordToRowCopier(new BytecodeAssembler(), metadata, writer.getMetadata(), toColumnFilter);
}
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
long timestamp = record.getTimestamp(timestampIndex);
if (timestamp > maxTimestamp) {
maxTimestamp = timestamp;
}
if (timestamp < minTimestamp) {
minTimestamp = timestamp;
}
Row row = writer.newRow(timestamp);
copier.copy(record, row);
row.append();
}
}
}
}
use of io.questdb.cairo.sql.RecordCursorFactory in project questdb by bluestreak01.
the class KeyedAggregationTest method testIntSymbolSumAddKeyTimeRange.
@Test
public void testIntSymbolSumAddKeyTimeRange() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table tab as (select rnd_symbol('s1','s2','s3', null) s1, rnd_double(2) val, timestamp_sequence(0, 1000000) t from long_sequence(1000000)) timestamp(t) partition by DAY", sqlExecutionContext);
compiler.compile("alter table tab add column s2 symbol cache", sqlExecutionContext);
compiler.compile("insert into tab select rnd_symbol('s1','s2','s3', null), rnd_double(2), timestamp_sequence(cast('1970-01-13T00:00:00.000000Z' as timestamp), 1000000), rnd_symbol('a1','a2','a3', null) s2 from long_sequence(1000000)", sqlExecutionContext);
// test with key falling within null columns
try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-04T12:01' and t < '1970-01-07T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
Record[] expected = new Record[] { new Record() {
@Override
public CharSequence getSym(int col) {
return null;
}
@Override
public double getDouble(int col) {
return 106413.99769604905;
}
} };
assertCursorRawRecords(expected, factory, false, true);
}
// / test key on overlap
try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-12T12:01' and t < '1970-01-14T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
Record[] expected = new Record[] { new Record() {
@Override
public CharSequence getSym(int col) {
return null;
}
@Override
public double getDouble(int col) {
return 15636.977658744854;
}
}, new Record() {
@Override
public CharSequence getSym(int col) {
return "a1";
}
@Override
public double getDouble(int col) {
return 13073.816187889399;
}
}, new Record() {
@Override
public CharSequence getSym(int col) {
return "a2";
}
@Override
public double getDouble(int col) {
return 13240.269899560482;
}
}, new Record() {
@Override
public CharSequence getSym(int col) {
return "a3";
}
@Override
public double getDouble(int col) {
return 13223.021189180576;
}
} };
assertCursorRawRecords(expected, factory, false, true);
}
});
}
Aggregations