use of io.questdb.cairo.sql.RecordCursor 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.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class TxSerializerTest method assertFirstColumnValueLong.
private void assertFirstColumnValueLong(String sql, long expected) throws SqlException {
try (RecordCursorFactory factory = compiler.compile(sql, sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(expected, cursor.getRecord().getLong(0));
}
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class TableReaderReloadBenchmark method setup.
@Setup(Level.Iteration)
public void setup() throws NumericException {
writer = new TableWriter(configuration, "test");
writer.truncate();
// create 10 partitions
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-01T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-02T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-03T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-04T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-05T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-06T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-07T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-08T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-09T00:00:00.000000Z"));
appendRow(TimestampFormatUtils.parseTimestamp("2012-03-10T00:00:00.000000Z"));
writer.commit();
reader = new TableReader(configuration, "test");
// ensure reader opens all partitions and maps all data
RecordCursor cursor = reader.getCursor();
Record record = cursor.getRecord();
while (cursor.hasNext()) {
sum += record.getTimestamp(0);
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class TelemetryJob method updateTelemetryConfig.
private TableWriter updateTelemetryConfig(SqlCompiler compiler, SqlExecutionContextImpl sqlExecutionContext, boolean enabled) throws SqlException {
final TableWriter configWriter = compiler.getEngine().getWriter(AllowAllCairoSecurityContext.INSTANCE, configTableName, WRITER_LOCK_REASON);
final CompiledQuery cc = compiler.compile(configTableName + " LIMIT -1", sqlExecutionContext);
try (final RecordCursor cursor = cc.getRecordCursorFactory().getCursor(sqlExecutionContext)) {
if (cursor.hasNext()) {
final Record record = cursor.getRecord();
final boolean _enabled = record.getBool(1);
Long256 l256 = record.getLong256A(0);
final CharSequence lastVersion = record.getSym(2);
// we need to update the table to reflect that
if (enabled != _enabled || !configuration.getBuildInformation().getQuestDbVersion().equals(lastVersion)) {
appendConfigRow(compiler, configWriter, l256, enabled);
LOG.info().$("instance config changes [id=").$256(l256.getLong0(), l256.getLong1(), 0, 0).$(", enabled=").$(enabled).$(']').$();
} else {
LOG.error().$("instance [id=").$256(l256.getLong0(), l256.getLong1(), 0, 0).$(", enabled=").$(enabled).$(']').$();
}
} else {
// if there are no record for telemetry id we need to create one using clocks
appendConfigRow(compiler, configWriter, null, enabled);
}
}
return configWriter;
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class CachedAnalyticRecordCursorFactory method getCursor.
@Override
public RecordCursor getCursor(SqlExecutionContext executionContext) throws SqlException {
recordChain.clear();
clearTrees();
resetFunctions();
final RecordCursor baseCursor = base.getCursor(executionContext);
// step #1: store source cursor in record list
// - add record list' row ids to all trees, which will put these row ids in necessary order
// for this we will be using out comparator, which helps tree compare long values
// based on record these values are addressing
long offset = -1;
final Record record = baseCursor.getRecord();
final Record chainRightRecord = recordChain.getRecordB();
if (orderedGroupCount > 0) {
while (baseCursor.hasNext()) {
offset = recordChain.put(record, offset);
recordChain.recordAt(recordChainRecord, offset);
for (int i = 0; i < orderedGroupCount; i++) {
orderedSources.getQuick(i).put(recordChainRecord, recordChain, chainRightRecord, comparators.getQuick(i));
}
}
} else {
while (baseCursor.hasNext()) {
offset = recordChain.put(record, offset);
}
}
if (orderedGroupCount > 0) {
for (int i = 0; i < orderedGroupCount; i++) {
final LongTreeChain tree = orderedSources.getQuick(i);
final ObjList<AnalyticFunction> functions = orderedFunctions.getQuick(i);
// step #2: populate all analytic functions with records in order of respective tree
final LongTreeChain.TreeCursor cursor = tree.getCursor();
final int functionCount = functions.size();
while (cursor.hasNext()) {
offset = cursor.next();
recordChain.recordAt(recordChainRecord, offset);
for (int j = 0; j < functionCount; j++) {
functions.getQuick(j).pass1(recordChainRecord, offset, recordChain);
}
}
}
}
// run pass1 for all unordered functions
if (unorderedFunctions != null) {
for (int j = 0, n = unorderedFunctions.size(); j < n; j++) {
final AnalyticFunction f = unorderedFunctions.getQuick(j);
recordChain.toTop();
while (recordChain.hasNext()) {
f.pass1(recordChainRecord, recordChainRecord.getRowId(), recordChain);
}
}
}
recordChain.toTop();
return recordChain;
}
Aggregations