Search in sources :

Example 1 with BytecodeAssembler

use of io.questdb.std.BytecodeAssembler in project questdb by bluestreak01.

the class O3CommitLagTest method insertUncommitted.

private void insertUncommitted(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, String sql, TableWriter writer) throws SqlException {
    minTimestamp = Long.MAX_VALUE;
    maxTimestamp = Long.MIN_VALUE;
    try (RecordCursorFactory factory = compiler.compile(sql, sqlExecutionContext).getRecordCursorFactory()) {
        RecordMetadata metadata = factory.getMetadata();
        int timestampIndex = writer.getMetadata().getTimestampIndex();
        EntityColumnFilter toColumnFilter = new EntityColumnFilter();
        toColumnFilter.of(metadata.getColumnCount());
        if (null == copier) {
            copier = SqlCompiler.assembleRecordToRowCopier(new BytecodeAssembler(), metadata, writer.getMetadata(), toColumnFilter);
        }
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            final Record record = cursor.getRecord();
            while (cursor.hasNext()) {
                long timestamp = record.getTimestamp(timestampIndex);
                if (timestamp > maxTimestamp) {
                    maxTimestamp = timestamp;
                }
                if (timestamp < minTimestamp) {
                    minTimestamp = timestamp;
                }
                Row row = writer.newRow(timestamp);
                copier.copy(record, row);
                row.append();
            }
        }
    }
}
Also used : RecordMetadata(io.questdb.cairo.sql.RecordMetadata) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Row(io.questdb.cairo.TableWriter.Row) BytecodeAssembler(io.questdb.std.BytecodeAssembler)

Example 2 with BytecodeAssembler

use of io.questdb.std.BytecodeAssembler in project questdb by bluestreak01.

the class RecordValueSinkFactoryTest method testSubset.

@Test
public void testSubset() {
    SingleColumnType keyTypes = new SingleColumnType(ColumnType.INT);
    try (TableModel model = new TableModel(configuration, "all", PartitionBy.NONE).col("int", ColumnType.INT).col("short", ColumnType.SHORT).col("byte", ColumnType.BYTE).col("double", ColumnType.DOUBLE).col("float", ColumnType.FLOAT).col("long", ColumnType.LONG).col("sym", ColumnType.SYMBOL).symbolCapacity(64).col("bool", ColumnType.BOOLEAN).col("date", ColumnType.DATE).col("ts", ColumnType.TIMESTAMP)) {
        CairoTestUtils.create(model);
    }
    final int N = 1024;
    final Rnd rnd = new Rnd();
    try (TableWriter writer = new TableWriter(configuration, "all")) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow();
            row.putInt(0, rnd.nextInt());
            row.putShort(1, rnd.nextShort());
            row.putByte(2, rnd.nextByte());
            row.putDouble(3, rnd.nextDouble());
            row.putFloat(4, rnd.nextFloat());
            row.putLong(5, rnd.nextLong());
            row.putSym(6, rnd.nextChars(10));
            row.putBool(7, rnd.nextBoolean());
            row.putDate(8, rnd.nextLong());
            row.putTimestamp(9, rnd.nextLong());
            row.append();
        }
        writer.commit();
    }
    try (TableReader reader = new TableReader(configuration, "all")) {
        ArrayColumnTypes valueTypes = new ArrayColumnTypes();
        valueTypes.add(ColumnType.BOOLEAN);
        valueTypes.add(ColumnType.TIMESTAMP);
        valueTypes.add(ColumnType.INT);
        try (final Map map = new FastMap(Numbers.SIZE_1MB, keyTypes, valueTypes, N, 0.5, 100)) {
            ListColumnFilter columnFilter = new ListColumnFilter();
            columnFilter.add(8);
            columnFilter.add(10);
            columnFilter.add(7);
            RecordValueSink sink = RecordValueSinkFactory.getInstance(new BytecodeAssembler(), reader.getMetadata(), columnFilter);
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            int index = 0;
            while (cursor.hasNext()) {
                MapKey key = map.withKey();
                key.putInt(index++);
                MapValue value = key.createValue();
                sink.copy(record, value);
            }
            Assert.assertEquals(N, index);
            rnd.reset();
            StaticSymbolTable symbolTable = reader.getSymbolMapReader(6);
            for (int i = 0; i < N; i++) {
                MapKey key = map.withKey();
                key.putInt(i);
                MapValue value = key.findValue();
                Assert.assertNotNull(value);
                // 0
                rnd.nextInt();
                // 1
                rnd.nextShort();
                // 2
                rnd.nextByte();
                // 3
                rnd.nextDouble();
                // 4
                rnd.nextFloat();
                // 5
                rnd.nextLong();
                // 6
                Assert.assertEquals(symbolTable.keyOf(rnd.nextChars(10)), value.getInt(2));
                // 7
                Assert.assertEquals(rnd.nextBoolean(), value.getBool(0));
                // 8
                rnd.nextLong();
                // 9
                Assert.assertEquals(rnd.nextLong(), value.getTimestamp(1));
            }
        }
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) BytecodeAssembler(io.questdb.std.BytecodeAssembler) StaticSymbolTable(io.questdb.cairo.sql.StaticSymbolTable) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 3 with BytecodeAssembler

use of io.questdb.std.BytecodeAssembler in project questdb by bluestreak01.

the class RecordValueSinkFactoryTest method testAllSupportedTypes.

@Test
public void testAllSupportedTypes() {
    SingleColumnType keyTypes = new SingleColumnType(ColumnType.INT);
    try (TableModel model = new TableModel(configuration, "all", PartitionBy.NONE).col("int", ColumnType.INT).col("short", ColumnType.SHORT).col("byte", ColumnType.BYTE).col("double", ColumnType.DOUBLE).col("float", ColumnType.FLOAT).col("long", ColumnType.LONG).col("sym", ColumnType.SYMBOL).symbolCapacity(64).col("bool", ColumnType.BOOLEAN).col("date", ColumnType.DATE).col("ts", ColumnType.TIMESTAMP)) {
        CairoTestUtils.create(model);
    }
    final int N = 1024;
    final Rnd rnd = new Rnd();
    try (TableWriter writer = new TableWriter(configuration, "all")) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow();
            row.putInt(0, rnd.nextInt());
            row.putShort(1, rnd.nextShort());
            row.putByte(2, rnd.nextByte());
            row.putDouble(3, rnd.nextDouble());
            row.putFloat(4, rnd.nextFloat());
            row.putLong(5, rnd.nextLong());
            row.putSym(6, rnd.nextChars(10));
            row.putBool(7, rnd.nextBoolean());
            row.putDate(8, rnd.nextLong());
            row.putTimestamp(9, rnd.nextLong());
            row.append();
        }
        writer.commit();
    }
    try (TableReader reader = new TableReader(configuration, "all")) {
        final SymbolAsIntTypes valueTypes = new SymbolAsIntTypes().of(reader.getMetadata());
        try (final Map map = new FastMap(Numbers.SIZE_1MB, keyTypes, valueTypes, N, 0.5, 100)) {
            EntityColumnFilter columnFilter = new EntityColumnFilter();
            columnFilter.of(reader.getMetadata().getColumnCount());
            RecordValueSink sink = RecordValueSinkFactory.getInstance(new BytecodeAssembler(), reader.getMetadata(), columnFilter);
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            int index = 0;
            while (cursor.hasNext()) {
                MapKey key = map.withKey();
                key.putInt(index++);
                MapValue value = key.createValue();
                sink.copy(record, value);
            }
            Assert.assertEquals(N, index);
            rnd.reset();
            StaticSymbolTable symbolTable = reader.getSymbolMapReader(6);
            for (int i = 0; i < N; i++) {
                MapKey key = map.withKey();
                key.putInt(i);
                MapValue value = key.findValue();
                Assert.assertNotNull(value);
                Assert.assertEquals(rnd.nextInt(), value.getInt(0));
                Assert.assertEquals(rnd.nextShort(), value.getShort(1));
                Assert.assertEquals(rnd.nextByte(), value.getByte(2));
                Assert.assertEquals(rnd.nextDouble(), value.getDouble(3), 0.000001);
                Assert.assertEquals(rnd.nextFloat(), value.getFloat(4), 0.000001f);
                Assert.assertEquals(rnd.nextLong(), value.getLong(5));
                Assert.assertEquals(symbolTable.keyOf(rnd.nextChars(10)), value.getInt(6));
                Assert.assertEquals(rnd.nextBoolean(), value.getBool(7));
                Assert.assertEquals(rnd.nextLong(), value.getDate(8));
                Assert.assertEquals(rnd.nextLong(), value.getTimestamp(9));
            }
        }
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) BytecodeAssembler(io.questdb.std.BytecodeAssembler) StaticSymbolTable(io.questdb.cairo.sql.StaticSymbolTable) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Aggregations

Record (io.questdb.cairo.sql.Record)3 RecordCursor (io.questdb.cairo.sql.RecordCursor)3 BytecodeAssembler (io.questdb.std.BytecodeAssembler)3 StaticSymbolTable (io.questdb.cairo.sql.StaticSymbolTable)2 Rnd (io.questdb.std.Rnd)2 Test (org.junit.Test)2 Row (io.questdb.cairo.TableWriter.Row)1 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)1 RecordMetadata (io.questdb.cairo.sql.RecordMetadata)1