use of com.questdb.common.Record in project questdb by bluestreak01.
the class RecordChainTest method testPseudoRandomAccess.
@Test
public void testPseudoRandomAccess() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 10000;
try (RecordChain chain = new RecordChain(metadata, SIZE_4M)) {
Record record = new TestRecord();
LongList rows = new LongList();
long o = -1L;
for (int i = 0; i < N; i++) {
o = chain.putRecord(record, o);
rows.add(o);
}
Assert.assertEquals(N, rows.size());
Record expected = new TestRecord();
for (int i = 0, n = rows.size(); i < n; i++) {
long row = rows.getQuick(i);
Record actual = chain.recordAt(row);
Assert.assertEquals(row, actual.getRowId());
assertSame(expected, actual);
}
Record expected2 = new TestRecord();
Record rec2 = chain.newRecord();
for (int i = 0, n = rows.size(); i < n; i++) {
long row = rows.getQuick(i);
chain.recordAt(rec2, row);
Assert.assertEquals(row, rec2.getRowId());
assertSame(expected2, rec2);
}
Record expected3 = new TestRecord();
Record rec3 = chain.getRecord();
for (int i = 0, n = rows.size(); i < n; i++) {
long row = rows.getQuick(i);
chain.recordAt(rec3, row);
Assert.assertEquals(row, rec3.getRowId());
assertSame(expected3, rec3);
}
}
});
}
use of com.questdb.common.Record in project questdb by bluestreak01.
the class HashJoinRecordSource method advanceSlaveCursor.
private void advanceSlaveCursor() {
Record rec = hashTableCursor.next();
nullableRecord.set_null((byRowId ? slaveCursor.recordAt(rec.getLong(0)) : rec) == null);
}
use of com.questdb.common.Record in project questdb by bluestreak01.
the class FilteredTableRecordCursorFactoryTest method testFactory.
@Test
public void testFactory() throws Exception {
TestUtils.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 * 4;
for (int i = 0; i < N; i++) {
symbols[i] = rnd.nextChars(8).toString();
}
rnd.reset();
// 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();
}
try (Engine engine = new Engine(configuration)) {
String value = symbols[N - 10];
SymbolIndexRowCursorFactory symbolIndexRowCursorFactory = new SymbolIndexRowCursorFactory(engine, "x", "b", value);
FullTableFrameCursorFactory dataFrameFactory = new FullTableFrameCursorFactory(engine, "x");
FilteredTableRecordCursorFactory factory = new FilteredTableRecordCursorFactory(dataFrameFactory, symbolIndexRowCursorFactory);
RecordCursor cursor = factory.getCursor();
while (cursor.hasNext()) {
Record record = cursor.next();
TestUtils.assertEquals(value, record.getSym(1));
}
cursor.releaseCursor();
}
});
}
use of com.questdb.common.Record in project questdb by bluestreak01.
the class AbstractOptimiserTest method assertString.
protected void assertString(String query, int columnIndex) throws ParserException {
try (RecordSource rs = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
RecordCursor cursor = rs.prepareCursor(FACTORY_CONTAINER.getFactory());
try {
while (cursor.hasNext()) {
Record r = cursor.next();
int len = r.getStrLen(columnIndex);
CharSequence s = r.getFlyweightStr(columnIndex);
if (s != null) {
CharSequence csB = r.getFlyweightStrB(columnIndex);
TestUtils.assertEquals(s, csB);
Assert.assertEquals(len, s.length());
Assert.assertFalse(s == csB);
} else {
Assert.assertEquals(-1, len);
Assert.assertNull(r.getFlyweightStr(columnIndex));
Assert.assertNull(r.getFlyweightStrB(columnIndex));
}
}
} finally {
cursor.releaseCursor();
}
}
}
use of com.questdb.common.Record in project questdb by bluestreak01.
the class AbstractOptimiserTest method assertSymbol.
public static void assertSymbol(String query, int columnIndex) throws ParserException {
try (RecordSource src = compiler.compile(FACTORY_CONTAINER.getFactory(), query)) {
RecordCursor cursor = src.prepareCursor(FACTORY_CONTAINER.getFactory());
try {
SymbolTable tab = cursor.getStorageFacade().getSymbolTable(columnIndex);
while (cursor.hasNext()) {
Record r = cursor.next();
TestUtils.assertEquals(r.getSym(columnIndex), tab.value(r.getInt(columnIndex)));
}
} finally {
cursor.releaseCursor();
}
}
}
Aggregations