use of com.questdb.common.Record in project questdb by bluestreak01.
the class CachedAnalyticRecordSource method prepareCursor.
@Override
public RecordCursor prepareCursor(ReaderFactory factory, CancellationHandler cancellationHandler) {
recordList.clear();
for (int i = 0; i < orderGroupCount; i++) {
RedBlackTree tree = orderedSources.getQuick(i);
if (tree != null) {
tree.clear();
}
}
for (int i = 0, n = functions.size(); i < n; i++) {
functions.getQuick(i).reset();
}
final RecordCursor cursor = recordSource.prepareCursor(factory, cancellationHandler);
try {
this.storageFacade.prepare(cursor.getStorageFacade());
// 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 rowid = -1;
while (cursor.hasNext()) {
cancellationHandler.check();
Record record = cursor.next();
rowid = recordList.append(record, rowid);
if (orderGroupCount > 0) {
for (int i = 0; i < orderGroupCount; i++) {
RedBlackTree tree = orderedSources.getQuick(i);
if (tree != null) {
tree.add(rowid);
}
}
}
}
for (int i = 0; i < orderGroupCount; i++) {
RedBlackTree tree = orderedSources.getQuick(i);
ObjList<AnalyticFunction> functions = functionGroups.getQuick(i);
if (tree != null) {
// step #2: populate all analytic functions with records in order of respective tree
RedBlackTree.LongIterator iterator = tree.iterator();
while (iterator.hasNext()) {
cancellationHandler.check();
Record record = recordList.recordAt(iterator.next());
for (int j = 0, n = functions.size(); j < n; j++) {
functions.getQuick(j).add(record);
}
}
} else {
// step #2: alternatively run record list through two-pass functions
for (int j = 0, n = functions.size(); j < n; j++) {
AnalyticFunction f = functions.getQuick(j);
if (f.getType() != AnalyticFunction.STREAM) {
recordList.toTop();
while (recordList.hasNext()) {
f.add(recordList.next());
}
}
}
}
}
} finally {
cursor.releaseCursor();
}
recordList.toTop();
setCursorAndPrepareFunctions();
return this;
}
use of com.questdb.common.Record in project questdb by bluestreak01.
the class CachedRowAnalyticRecordSource method prepareCursor.
@Override
public RecordCursor prepareCursor(ReaderFactory factory, CancellationHandler cancellationHandler) {
recordList.clear();
for (int i = 0; i < orderGroupCount; i++) {
RedBlackTree tree = orderedSources.getQuick(i);
if (tree != null) {
tree.clear();
}
}
for (int i = 0, n = functions.size(); i < n; i++) {
functions.getQuick(i).reset();
}
final RecordCursor cursor = delegate.prepareCursor(factory, cancellationHandler);
this.parentCursor = cursor;
this.storageFacade.prepare(cursor.getStorageFacade());
// red&black trees, one for each comparator where comparator is not null
for (int i = 0; i < orderGroupCount; i++) {
RedBlackTree tree = orderedSources.getQuick(i);
if (tree != null) {
((MyComparator) tree.getComparator()).setCursor(cursor);
}
}
// 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 rowid = -1;
while (cursor.hasNext()) {
cancellationHandler.check();
Record record = cursor.next();
long row = record.getRowId();
rowid = recordList.append(fakeRecord.of(row), rowid);
if (orderGroupCount > 0) {
for (int i = 0; i < orderGroupCount; i++) {
RedBlackTree tree = orderedSources.getQuick(i);
if (tree != null) {
tree.add(row);
}
}
}
}
for (int i = 0; i < orderGroupCount; i++) {
RedBlackTree tree = orderedSources.getQuick(i);
ObjList<AnalyticFunction> functions = functionGroups.getQuick(i);
if (tree != null) {
// step #2: populate all analytic functions with records in order of respective tree
RedBlackTree.LongIterator iterator = tree.iterator();
while (iterator.hasNext()) {
cancellationHandler.check();
Record record = cursor.recordAt(iterator.next());
for (int j = 0, n = functions.size(); j < n; j++) {
functions.getQuick(j).add(record);
}
}
} else {
// step #2: alternatively run record list through two-pass functions
for (int j = 0, n = functions.size(); j < n; j++) {
AnalyticFunction f = functions.getQuick(j);
if (f.getType() != AnalyticFunction.STREAM) {
recordList.toTop();
while (recordList.hasNext()) {
f.add(cursor.recordAt(recordList.next().getLong(0)));
}
}
}
}
}
recordList.toTop();
for (int i = 0, n = functions.size(); i < n; i++) {
functions.getQuick(i).prepare(cursor);
}
return this;
}
use of com.questdb.common.Record in project questdb by bluestreak01.
the class HashJoinRecordSource method buildHashTable.
private void buildHashTable(CancellationHandler cancellationHandler) {
for (Record r : slaveCursor) {
cancellationHandler.check();
recordMap.locate(slaveCopier, r);
if (byRowId) {
recordMap.add(fakeRecord.of(r.getRowId()));
} else {
recordMap.add(r);
}
}
}
use of com.questdb.common.Record in project questdb by bluestreak01.
the class HashJoinRecordSource method hasNext0.
private boolean hasNext0() {
while (masterCursor.hasNext()) {
Record r = masterCursor.next();
recordMap.locate(masterCopier, r);
hashTableCursor = recordMap.get();
if (hashTableCursor.hasNext()) {
advanceSlaveCursor();
return true;
} else if (outer) {
hashTableCursor = null;
nullableRecord.set_null(true);
return true;
}
}
return false;
}
Aggregations