Search in sources :

Example 6 with IntList

use of com.questdb.std.IntList 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();
            }
        }
    });
}
Also used : JournalException(com.questdb.std.ex.JournalException) LongList(com.questdb.std.LongList) IntList(com.questdb.std.IntList)

Example 7 with IntList

use of com.questdb.std.IntList in project questdb by bluestreak01.

the class ComparatorCompilerTest method testCompileLarge.

@Test
public void testCompileLarge() {
    TestRecordMetadata m = new TestRecordMetadata();
    for (int i = 0; i < 155; i++) {
        m.addDistinct();
    }
    IntList indices = new IntList(m.getColumnCount());
    for (int i = 0, n = m.getColumnCount(); i < n; i++) {
        indices.add(i + 1);
    }
    RecordComparator rc = cc.compile(m, indices);
    Assert.assertNotNull(rc);
}
Also used : IntList(com.questdb.std.IntList) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 8 with IntList

use of com.questdb.std.IntList in project questdb by bluestreak01.

the class ComparatorCompilerTest method testAllGetters.

@Test
public void testAllGetters() throws Exception {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz").$bool("bool").$byte("byte").$double("double").$float("float").$int("int").$long("long").$date("date").$short("short").$str("str").$sym("sym").$())) {
        JournalEntryWriter ew = w.entryWriter();
        ew.putBool(0, true);
        ew.put(1, (byte) 13);
        ew.putDouble(2, 20.12);
        ew.putFloat(3, 10.15f);
        ew.putInt(4, 4);
        ew.putLong(5, 9988908080988890L);
        ew.putDate(6, 88979879L);
        ew.putShort(7, (short) 902);
        ew.putStr(8, "complexity made simple");
        ew.putSym(9, "questdb");
        ew.append();
        ew = w.entryWriter();
        ew.put(1, (byte) 13);
        ew.putDouble(2, 20.12);
        ew.putFloat(3, 10.15f);
        ew.putInt(4, 4);
        ew.putLong(5, 9988908080988890L);
        ew.putDate(6, 88979879L);
        ew.putShort(7, (short) 902);
        ew.putStr(8, "complexity made simple");
        ew.putSym(9, "appsicle");
        ew.append();
        w.commit();
        IntList indices = new IntList();
        for (int i = 0, n = w.getMetadata().getColumnCount(); i < n; i++) {
            indices.add(i + 1);
        }
        RecordSource rs = compileSource("xyz");
        RecordComparator rc = cc.compile(rs.getMetadata(), indices);
        RBTreeSortedRecordSource map = new RBTreeSortedRecordSource(rs, rc, 1024 * 1024, 4 * 1024 * 1024);
        sink.clear();
        printer.print(map, FACTORY_CONTAINER.getFactory());
    }
    TestUtils.assertEquals("false\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tappsicle\n" + "true\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tquestdb\n", sink);
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordSource(com.questdb.ql.RecordSource) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) JournalEntryWriter(com.questdb.store.JournalEntryWriter) IntList(com.questdb.std.IntList) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 9 with IntList

use of com.questdb.std.IntList in project questdb by bluestreak01.

the class ComparatorCompilerTest method testCompileAll.

@Test
public void testCompileAll() {
    TestRecordMetadata m = new TestRecordMetadata().addDistinct();
    IntList indices = new IntList(m.getColumnCount());
    for (int i = 0, n = m.getColumnCount(); i < n; i++) {
        indices.add(i + 1);
    }
    RecordComparator rc = cc.compile(m, indices);
    Assert.assertNotNull(rc);
}
Also used : IntList(com.questdb.std.IntList) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 10 with IntList

use of com.questdb.std.IntList in project questdb by bluestreak01.

the class ComparatorCompilerTest method testTwoClassesSameClassloader.

@Test
public void testTwoClassesSameClassloader() {
    TestRecordMetadata m = new TestRecordMetadata();
    for (int i = 0; i < 155; i++) {
        m.asType(ColumnType.STRING);
    }
    IntList indices = new IntList(m.getColumnCount());
    for (int i = 0, n = m.getColumnCount(); i < n; i++) {
        indices.add(i + 1);
    }
    RecordComparator rc1 = cc.compile(m, indices);
    RecordComparator rc2 = cc.compile(m, indices);
    Assert.assertNotNull(rc1);
    Assert.assertNotNull(rc2);
}
Also used : IntList(com.questdb.std.IntList) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Aggregations

IntList (com.questdb.std.IntList)11 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)6 Test (org.junit.Test)6 BytecodeAssembler (com.questdb.std.BytecodeAssembler)4 Album (com.questdb.model.Album)3 Band (com.questdb.model.Band)3 HashJoinRecordSource (com.questdb.ql.join.HashJoinRecordSource)3 RecordKeyCopierCompiler (com.questdb.ql.map.RecordKeyCopierCompiler)3 SelectedColumnsRecordSource (com.questdb.ql.select.SelectedColumnsRecordSource)3 StringSink (com.questdb.std.str.StringSink)3 RecordSource (com.questdb.ql.RecordSource)2 JournalEntryWriter (com.questdb.store.JournalEntryWriter)2 JournalWriter (com.questdb.store.JournalWriter)2 Record (com.questdb.common.Record)1 RecordCursor (com.questdb.common.RecordCursor)1 LongList (com.questdb.std.LongList)1 JournalException (com.questdb.std.ex.JournalException)1 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)1