Search in sources :

Example 1 with DataFrame

use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.

the class LatestByAllRecordCursor method buildTreeMap.

@Override
protected void buildTreeMap(SqlExecutionContext executionContext) {
    DataFrame frame;
    try {
        while ((frame = this.dataFrameCursor.next()) != null) {
            final int partitionIndex = frame.getPartitionIndex();
            final long rowLo = frame.getRowLo();
            final long rowHi = frame.getRowHi() - 1;
            recordA.jumpTo(frame.getPartitionIndex(), rowHi);
            for (long row = rowHi; row >= rowLo; row--) {
                recordA.setRecordIndex(row);
                MapKey key = map.withKey();
                key.put(recordA, recordSink);
                if (key.create()) {
                    rows.add(Rows.toRowID(partitionIndex, row));
                }
            }
        }
    } finally {
        map.clear();
    }
}
Also used : MapKey(io.questdb.cairo.map.MapKey) DataFrame(io.questdb.cairo.sql.DataFrame)

Example 2 with DataFrame

use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.

the class LatestByValueFilteredRecordCursor method findRecord.

private void findRecord() {
    empty = true;
    DataFrame frame;
    OUT: while ((frame = this.dataFrameCursor.next()) != null) {
        final long rowLo = frame.getRowLo();
        final long rowHi = frame.getRowHi() - 1;
        recordA.jumpTo(frame.getPartitionIndex(), rowHi);
        for (long row = rowHi; row >= rowLo; row--) {
            recordA.setRecordIndex(row);
            if (filter.getBool(recordA)) {
                int key = recordA.getInt(columnIndex);
                if (key == symbolKey) {
                    empty = false;
                    break OUT;
                }
            }
        }
    }
}
Also used : DataFrame(io.questdb.cairo.sql.DataFrame)

Example 3 with DataFrame

use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.

the class LatestByValueRecordCursor method findRecord.

private void findRecord() {
    empty = true;
    DataFrame frame;
    OUT: while ((frame = this.dataFrameCursor.next()) != null) {
        final long rowLo = frame.getRowLo();
        final long rowHi = frame.getRowHi() - 1;
        recordA.jumpTo(frame.getPartitionIndex(), rowHi);
        for (long row = rowHi; row >= rowLo; row--) {
            recordA.setRecordIndex(row);
            int key = recordA.getInt(columnIndex);
            if (key == symbolKey) {
                empty = false;
                break OUT;
            }
        }
    }
}
Also used : DataFrame(io.questdb.cairo.sql.DataFrame)

Example 4 with DataFrame

use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.

the class LatestByValuesRecordCursor method buildTreeMap.

@Override
protected void buildTreeMap(SqlExecutionContext executionContext) {
    prepare();
    DataFrame frame;
    while ((frame = this.dataFrameCursor.next()) != null) {
        final int partitionIndex = frame.getPartitionIndex();
        final long rowLo = frame.getRowLo();
        final long rowHi = frame.getRowHi() - 1;
        recordA.jumpTo(frame.getPartitionIndex(), rowHi);
        for (long row = rowHi; row >= rowLo; row--) {
            recordA.setRecordIndex(row);
            int key = TableUtils.toIndexKey(recordA.getInt(columnIndex));
            int index = map.keyIndex(key);
            if (index < 0 && map.valueAt(index) == 0) {
                rows.add(Rows.toRowID(partitionIndex, row));
                map.putAt(index, key, 1);
            }
        }
    }
}
Also used : DataFrame(io.questdb.cairo.sql.DataFrame)

Example 5 with DataFrame

use of io.questdb.cairo.sql.DataFrame in project questdb by bluestreak01.

the class FullFwdDataFrameCursorFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    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 * 10;
        for (int i = 0; i < N; i++) {
            symbols[i] = rnd.nextChars(8).toString();
        }
        // 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();
        }
        FullFwdDataFrameCursorFactory factory = new FullFwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, 0);
        long count = 0;
        try (DataFrameCursor cursor = factory.getCursor(AllowAllSqlSecurityContext.INSTANCE)) {
            DataFrame frame;
            while ((frame = cursor.next()) != null) {
                count += frame.getRowHi() - frame.getRowLo();
            }
        }
        Assert.assertEquals(0, engine.getBusyReaderCount());
        Assert.assertEquals(M, count);
        try (TableWriter writer = engine.getWriter(AllowAllCairoSecurityContext.INSTANCE, "x", "testing")) {
            writer.removeColumn("b");
        }
        try {
            factory.getCursor(AllowAllSqlSecurityContext.INSTANCE);
            Assert.fail();
        } catch (ReaderOutOfDateException ignored) {
        }
    });
}
Also used : DataFrameCursor(io.questdb.cairo.sql.DataFrameCursor) Rnd(io.questdb.std.Rnd) DataFrame(io.questdb.cairo.sql.DataFrame) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException) Test(org.junit.Test)

Aggregations

DataFrame (io.questdb.cairo.sql.DataFrame)13 BitmapIndexReader (io.questdb.cairo.BitmapIndexReader)4 RowCursor (io.questdb.cairo.sql.RowCursor)3 MapKey (io.questdb.cairo.map.MapKey)2 MessageBus (io.questdb.MessageBus)1 TableReader (io.questdb.cairo.TableReader)1 DataFrameCursor (io.questdb.cairo.sql.DataFrameCursor)1 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)1 MemoryR (io.questdb.cairo.vm.api.MemoryR)1 Sequence (io.questdb.mp.Sequence)1 Rnd (io.questdb.std.Rnd)1 LatestByTask (io.questdb.tasks.LatestByTask)1 Test (org.junit.Test)1