Search in sources :

Example 26 with Record

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;
}
Also used : RedBlackTree(com.questdb.std.RedBlackTree) RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record)

Example 27 with Record

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;
}
Also used : RedBlackTree(com.questdb.std.RedBlackTree) RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record) FakeRecord(com.questdb.ql.join.hash.FakeRecord)

Example 28 with Record

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);
        }
    }
}
Also used : Record(com.questdb.common.Record) FakeRecord(com.questdb.ql.join.hash.FakeRecord) NullableRecord(com.questdb.ql.NullableRecord)

Example 29 with Record

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;
}
Also used : Record(com.questdb.common.Record) FakeRecord(com.questdb.ql.join.hash.FakeRecord) NullableRecord(com.questdb.ql.NullableRecord)

Aggregations

Record (com.questdb.common.Record)29 RecordCursor (com.questdb.common.RecordCursor)19 Test (org.junit.Test)13 RecordSource (com.questdb.ql.RecordSource)10 JournalWriter (com.questdb.store.JournalWriter)5 AbstractTest (com.questdb.test.tools.AbstractTest)5 FakeRecord (com.questdb.ql.join.hash.FakeRecord)4 JournalEntryWriter (com.questdb.store.JournalEntryWriter)4 NullableRecord (com.questdb.ql.NullableRecord)3 Rnd (com.questdb.std.Rnd)3 SymbolTable (com.questdb.common.SymbolTable)2 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)2 LongList (com.questdb.std.LongList)2 RedBlackTree (com.questdb.std.RedBlackTree)2 ArrayList (java.util.ArrayList)2 RecordCursorFactory (com.questdb.cairo.sql.RecordCursorFactory)1 QueryCompiler (com.questdb.parser.sql.QueryCompiler)1 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)1 AsOfPartitionedJoinRecordSource (com.questdb.ql.join.AsOfPartitionedJoinRecordSource)1 BytecodeAssembler (com.questdb.std.BytecodeAssembler)1