use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.
the class LatestByAllRecordCursor method buildTreeMap.
@Override
protected void buildTreeMap(SqlExecutionContext executionContext) {
DataFrame frame;
try {
while ((frame = this.dataFrameCursor.next()) != null) {
final int partitionIndex = frame.getPartitionIndex();
final long rowLo = frame.getRowLo();
final long rowHi = frame.getRowHi() - 1;
recordA.jumpTo(frame.getPartitionIndex(), rowHi);
for (long row = rowHi; row >= rowLo; row--) {
recordA.setRecordIndex(row);
MapKey key = map.withKey();
key.put(recordA, recordSink);
if (key.create()) {
rows.add(Rows.toRowID(partitionIndex, row));
}
}
}
} finally {
map.clear();
}
}
use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.
the class LatestByValueFilteredRecordCursor method findRecord.
private void findRecord() {
empty = true;
DataFrame frame;
OUT: while ((frame = this.dataFrameCursor.next()) != null) {
final long rowLo = frame.getRowLo();
final long rowHi = frame.getRowHi() - 1;
recordA.jumpTo(frame.getPartitionIndex(), rowHi);
for (long row = rowHi; row >= rowLo; row--) {
recordA.setRecordIndex(row);
if (filter.getBool(recordA)) {
int key = recordA.getInt(columnIndex);
if (key == symbolKey) {
empty = false;
break OUT;
}
}
}
}
}
use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.
the class LatestByValueRecordCursor method findRecord.
private void findRecord() {
empty = true;
DataFrame frame;
OUT: while ((frame = this.dataFrameCursor.next()) != null) {
final long rowLo = frame.getRowLo();
final long rowHi = frame.getRowHi() - 1;
recordA.jumpTo(frame.getPartitionIndex(), rowHi);
for (long row = rowHi; row >= rowLo; row--) {
recordA.setRecordIndex(row);
int key = recordA.getInt(columnIndex);
if (key == symbolKey) {
empty = false;
break OUT;
}
}
}
}
use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.
the class LatestByValuesRecordCursor method buildTreeMap.
@Override
protected void buildTreeMap(SqlExecutionContext executionContext) {
prepare();
DataFrame frame;
while ((frame = this.dataFrameCursor.next()) != null) {
final int partitionIndex = frame.getPartitionIndex();
final long rowLo = frame.getRowLo();
final long rowHi = frame.getRowHi() - 1;
recordA.jumpTo(frame.getPartitionIndex(), rowHi);
for (long row = rowHi; row >= rowLo; row--) {
recordA.setRecordIndex(row);
int key = TableUtils.toIndexKey(recordA.getInt(columnIndex));
int index = map.keyIndex(key);
if (index < 0 && map.valueAt(index) == 0) {
rows.add(Rows.toRowID(partitionIndex, row));
map.putAt(index, key, 1);
}
}
}
}
use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.
the class FullFwdDataFrameCursorFactoryTest method testFactory.
@Test
public void testFactory() throws Exception {
assertMemoryLeak(() -> {
final int N = 100;
// separate two symbol columns with primitive. It will make problems apparent if index does not shift correctly
try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.STRING).col("b", ColumnType.SYMBOL).indexed(true, N / 4).col("i", ColumnType.INT).col("c", ColumnType.SYMBOL).indexed(true, N / 4).timestamp()) {
CairoTestUtils.create(model);
}
final Rnd rnd = new Rnd();
final String[] symbols = new String[N];
final int M = 1000;
final long increment = 1000000 * 60L * 10;
for (int i = 0; i < N; i++) {
symbols[i] = rnd.nextChars(8).toString();
}
// prepare the data
long timestamp = 0;
try (TableWriter writer = new TableWriter(configuration, "x")) {
for (int i = 0; i < M; i++) {
TableWriter.Row row = writer.newRow(timestamp += increment);
row.putStr(0, rnd.nextChars(20));
row.putSym(1, symbols[rnd.nextPositiveInt() % N]);
row.putInt(2, rnd.nextInt());
row.putSym(3, symbols[rnd.nextPositiveInt() % N]);
row.append();
}
writer.commit();
}
FullFwdDataFrameCursorFactory factory = new FullFwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, 0);
long count = 0;
try (DataFrameCursor cursor = factory.getCursor(AllowAllSqlSecurityContext.INSTANCE)) {
DataFrame frame;
while ((frame = cursor.next()) != null) {
count += frame.getRowHi() - frame.getRowLo();
}
}
Assert.assertEquals(0, engine.getBusyReaderCount());
Assert.assertEquals(M, count);
try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "x", "testing")) {
writer.removeColumn("b");
}
try {
factory.getCursor(AllowAllSqlSecurityContext.INSTANCE);
Assert.fail();
} catch (ReaderOutOfDateException ignored) {
}
});
}
Aggregations