Search in sources :

Example 1 with IntFunction

use of io.questdb.griffin.engine.functions.IntFunction in project questdb by bluestreak01.

the class RecordChainTest method testSkipAndRefill.

@Test
public void testSkipAndRefill() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        GenericRecordMetadata metadata = new GenericRecordMetadata();
        metadata.add(new TableColumnMetadata("x", 1, ColumnType.LONG));
        metadata.add(new TableColumnMetadata("y", 2, ColumnType.INT));
        metadata.add(new TableColumnMetadata("z", 3, ColumnType.INT));
        ListColumnFilter filter = new ListColumnFilter();
        filter.add(1);
        filter.add(-2);
        filter.add(3);
        RecordSink sink = RecordSinkFactory.getInstance(asm, metadata, filter, false);
        long[] cols = new long[metadata.columnCount];
        final ObjList<Function> funcs = new ObjList<>();
        funcs.add(new LongFunction() {

            @Override
            public long getLong(Record rec) {
                return cols[0];
            }
        });
        funcs.add(null);
        funcs.add(new IntFunction() {

            @Override
            public int getInt(Record rec) {
                return (int) cols[2];
            }
        });
        final VirtualRecord rec = new VirtualRecord(funcs);
        try (RecordChain chain = new RecordChain(metadata, sink, SIZE_4M, Integer.MAX_VALUE)) {
            long o = -1;
            cols[0] = 100;
            cols[2] = 200;
            o = chain.put(rec, o);
            // out of band update of column
            Unsafe.getUnsafe().putInt(chain.addressOf(chain.getOffsetOfColumn(o, 1)), 55);
            cols[0] = 110;
            cols[2] = 210;
            o = chain.put(rec, o);
            Unsafe.getUnsafe().putInt(chain.getAddress(o, 1), 66);
            AbstractCairoTest.sink.clear();
            chain.toTop();
            final Record r = chain.getRecord();
            while (chain.hasNext()) {
                printer.print(r, metadata, AbstractCairoTest.sink);
            }
            String expected = "100\t55\t200\n" + "110\t66\t210\n";
            TestUtils.assertEquals(expected, AbstractCairoTest.sink);
        }
    });
}
Also used : LongFunction(io.questdb.griffin.engine.functions.LongFunction) IntFunction(io.questdb.griffin.engine.functions.IntFunction) LongFunction(io.questdb.griffin.engine.functions.LongFunction) IntFunction(io.questdb.griffin.engine.functions.IntFunction) Test(org.junit.Test)

Aggregations

IntFunction (io.questdb.griffin.engine.functions.IntFunction)1 LongFunction (io.questdb.griffin.engine.functions.LongFunction)1 Test (org.junit.Test)1