use of com.questdb.std.LongList in project questdb by bluestreak01.
the class MultiIntervalPartitionSourceTest method testIntervalMerge.
@Test
public void testIntervalMerge() throws Exception {
StringSink sink = new StringSink();
try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
TestUtils.generateQuoteData(w, 600, DateFormatUtils.parseDateTime("2014-03-10T02:00:00.000Z"), Dates.MINUTE_MILLIS);
w.commit();
RecordSourcePrinter p = new RecordSourcePrinter(sink);
LongList intervals = new LongList();
intervals.add(DateFormatUtils.parseDateTime("2014-03-10T07:00:00.000Z"));
intervals.add(DateFormatUtils.parseDateTime("2014-03-10T07:15:00.000Z"));
p.print(new JournalRecordSource(new MultiIntervalPartitionSource(new JournalPartitionSource(w.getMetadata(), true), intervals), new AllRowSource()), getFactory());
}
final String expected = "2014-03-10T07:00:00.000Z\tGKN.L\t290.000000000000\t320.000000000000\t1070060020\t627764827\tFast trading\tLXE\n" + "2014-03-10T07:01:00.000Z\tLLOY.L\t0.001271238521\t0.000000010817\t855783502\t444545168\tFast trading\tLXE\n" + "2014-03-10T07:02:00.000Z\tRRS.L\t0.000010917804\t272.000000000000\t1212565949\t1829154977\tFast trading\tLXE\n" + "2014-03-10T07:03:00.000Z\tTLW.L\t245.300086975098\t363.160156250000\t1722093204\t448833342\tFast trading\tLXE\n" + "2014-03-10T07:04:00.000Z\tTLW.L\t0.025095539168\t0.000000122058\t1703832336\t180642477\tFast trading\tLXE\n" + "2014-03-10T07:05:00.000Z\tADM.L\t902.500000000000\t24.333267211914\t781438951\t502201118\tFast trading\tLXE\n" + "2014-03-10T07:06:00.000Z\tAGK.L\t144.695419311523\t0.000039814179\t639071723\t1848238665\tFast trading\tLXE\n" + "2014-03-10T07:07:00.000Z\tLLOY.L\t0.000035416079\t15.248794555664\t1987214795\t856360285\tFast trading\tLXE\n" + "2014-03-10T07:08:00.000Z\tAGK.L\t0.207015849650\t0.199165701866\t1090730005\t1076974002\tFast trading\tLXE\n" + "2014-03-10T07:09:00.000Z\tLLOY.L\t447.510742187500\t209.001678466797\t136979290\t653726755\tFast trading\tLXE\n" + "2014-03-10T07:10:00.000Z\tBT-A.L\t662.032958984375\t0.000000007138\t1140333902\t1156896957\tFast trading\tLXE\n" + "2014-03-10T07:11:00.000Z\tAGK.L\t512.000000000000\t33.973937988281\t1723438228\t349327821\tFast trading\tLXE\n" + "2014-03-10T07:12:00.000Z\tWTB.L\t384.000000000000\t0.000000832384\t2145991300\t1388483923\tFast trading\tLXE\n" + "2014-03-10T07:13:00.000Z\tTLW.L\t0.000000093063\t0.000071085584\t1186156647\t1143726003\tFast trading\tLXE\n" + "2014-03-10T07:14:00.000Z\tAGK.L\t0.006215140224\t0.000000004051\t2086874501\t1272052914\tFast trading\tLXE\n" + "2014-03-10T07:15:00.000Z\tBP.L\t642.189208984375\t148.932441711426\t1552494421\t348870719\tFast trading\tLXE\n";
Assert.assertEquals(expected, sink.toString());
}
use of com.questdb.std.LongList in project questdb by bluestreak01.
the class RecordListTest method writeAndReadRecords.
private <T> void writeAndReadRecords(JournalWriter<T> journal, int count, int pageSize, RecordGenerator<T> generator) throws IOException, JournalException, ParserException {
try {
for (int i = 0; i < count; i++) {
journal.append(generator.generate(i));
}
journal.commit();
try (RecordList records = new RecordList(journal.getMetadata(), pageSize)) {
LongList offsets = new LongList();
try (RecordSource rs = compiler.compile(getFactory(), journal.getLocation().getName())) {
long o = -1;
RecordCursor cursor = rs.prepareCursor(getFactory());
try {
for (Record rec : cursor) {
offsets.add(o = records.append(rec, o));
}
} finally {
cursor.releaseCursor();
}
}
int i = 0;
records.toTop();
while (records.hasNext()) {
generator.assertRecord(records.next(), i++);
}
}
} finally {
journal.close();
}
}
use of com.questdb.std.LongList in project questdb by bluestreak01.
the class ResultSet method shuffle.
public ResultSet<T> shuffle(Rnd rnd) {
LongList rows = new LongList(this.rowIDs);
rows.shuffle(rnd);
return new ResultSet<>(journal, rows);
}
use of com.questdb.std.LongList in project questdb by bluestreak01.
the class QueryAllResultSetBuilder method read.
@Override
public void read(long lo, long hi) {
for (int i = 0, sz = symbolKeys.size(); i < sz; i++) {
int symbolKey = symbolKeys.getQuick(i);
if (index.contains(symbolKey)) {
if (searchIndices.length > 0) {
for (int k = 0; k < searchIndices.length; k++) {
if (searchIndices[k].contains(filterSymbolKeys.getQuick(k))) {
LongList searchLocalRowIDs = searchIndices[k].getValues(filterSymbolKeys.getQuick(k));
IndexCursor cursor = index.cursor(symbolKey);
while (cursor.hasNext()) {
long localRowID = cursor.next();
if (localRowID < lo) {
break;
}
if (localRowID <= hi && searchLocalRowIDs.binarySearch(localRowID) >= 0) {
result.add(Rows.toRowID(partition.getPartitionIndex(), localRowID));
}
}
}
}
} else {
IndexCursor cursor = index.cursor(symbolKey);
result.ensureCapacity((int) cursor.size());
while (cursor.hasNext()) {
long localRowID = cursor.next();
if (localRowID >= lo && localRowID <= hi) {
result.add(Rows.toRowID(partition.getPartitionIndex(), localRowID));
}
}
}
}
}
}
use of com.questdb.std.LongList in project questdb by bluestreak01.
the class QueryHeadBuilderImpl method asResultSet.
public UnorderedResultSet<T> asResultSet() throws JournalException {
final int minPartitionIndex;
final long minLocalRowID;
if (minRowID == -1L) {
minPartitionIndex = 0;
minLocalRowID = -1L;
} else {
minPartitionIndex = Rows.toPartitionIndex(minRowID);
minLocalRowID = Rows.toLocalRowID(minRowID);
}
zone1Keys.clear(symbolKeys.size());
zone2Keys.clear(symbolKeys.size());
zone1Keys.addAll(symbolKeys);
// noinspection ConstantConditions
return journal.iteratePartitionsDesc(new UnorderedResultSetBuilder<T>(interval) {
private final KVIndex[] filterKVIndexes = new KVIndex[filterSymbolKeys.size()];
private final LongList[] filterSymbolRows = new LongList[filterSymbolKeys.size()];
private IntList keys = zone1Keys;
private IntList remainingKeys = zone2Keys;
@Override
public Accept accept(Partition<T> partition) throws JournalException {
super.accept(partition);
return keys.size() == 0 || partition.getPartitionIndex() < minPartitionIndex ? Accept.BREAK : Accept.CONTINUE;
}
@Override
public void read(long lo, long hi) throws JournalException {
KVIndex index = partition.getIndexForColumn(symbolColumnIndex);
boolean filterOk = true;
for (int i = 0; i < filterSymbols.size(); i++) {
filterKVIndexes[i] = partition.getIndexForColumn(filterSymbols.getQuick(i));
int filterKey = filterSymbolKeys.getQuick(i);
if (filterKVIndexes[i].contains(filterKey)) {
filterSymbolRows[i].ensureCapacity(filterKVIndexes[i].getValueCount(filterKey));
filterKVIndexes[i].getValues(filterKey, filterSymbolRows[i]);
} else {
filterOk = false;
break;
}
}
if (filterOk) {
for (int k = 0; k < keys.size(); k++) {
int key = keys.getQuick(k);
boolean found = false;
IndexCursor cursor = index.cursor(key);
NEXT_KEY: while (cursor.hasNext()) {
long localRowID = cursor.next();
if (localRowID <= hi && localRowID >= lo && (partition.getPartitionIndex() > minPartitionIndex || localRowID > minLocalRowID)) {
boolean matches = true;
for (int i = 0; i < filterSymbolRows.length; i++) {
if (filterSymbolRows[i].binarySearch(localRowID) < 0) {
matches = false;
if (strict) {
found = true;
break NEXT_KEY;
} else {
break;
}
}
}
if (matches) {
result.add(Rows.toRowID(partition.getPartitionIndex(), localRowID));
found = true;
break;
}
} else if (localRowID < lo || (partition.getPartitionIndex() <= minPartitionIndex && localRowID <= minLocalRowID)) {
// localRowID is only going to get lower, so fail fast
found = true;
break;
}
}
if (!found) {
remainingKeys.add(key);
}
}
IntList temp = keys;
keys = remainingKeys;
remainingKeys = temp;
remainingKeys.clear();
}
}
{
for (int i = 0; i < filterSymbolRows.length; i++) {
filterSymbolRows[i] = new LongList();
}
}
});
}
Aggregations