Search in sources :

Example 91 with RecordCursor

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

the class JsonQueryProcessorState method onNoMoreData.

private void onNoMoreData() {
    long nanos = nanosecondClock.getTicks();
    if (countRows) {
        // this is the tail end of the cursor
        // we don't need to read records, just round up record count
        final RecordCursor cursor = this.cursor;
        final long size = cursor.size();
        if (size < 0) {
            LOG.info().$("counting").$();
            long count = 1;
            while (cursor.hasNext()) {
                count++;
            }
            this.count += count;
        } else {
            this.count = size;
        }
    }
    recordCountNanos = nanosecondClock.getTicks() - nanos;
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor)

Example 92 with RecordCursor

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

the class FastMapTest method testValueRandomWrite.

@Test
public void testValueRandomWrite() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 10000;
        final Rnd rnd = new Rnd();
        TestRecord.ArrayBinarySequence binarySequence = new TestRecord.ArrayBinarySequence();
        createTestTable(N, rnd, binarySequence);
        BytecodeAssembler asm = new BytecodeAssembler();
        try (TableReader reader = new TableReader(configuration, "x")) {
            ListColumnFilter listColumnFilter = new ListColumnFilter();
            for (int i = 0, n = reader.getMetadata().getColumnCount(); i < n; i++) {
                listColumnFilter.add(i + 1);
            }
            try (FastMap map = new FastMap(Numbers.SIZE_1MB, new SymbolAsIntTypes().of(reader.getMetadata()), new ArrayColumnTypes().add(ColumnType.LONG).add(ColumnType.INT).add(ColumnType.SHORT).add(ColumnType.BYTE).add(ColumnType.FLOAT).add(ColumnType.DOUBLE).add(ColumnType.DATE).add(ColumnType.TIMESTAMP).add(ColumnType.BOOLEAN), N, 0.9f, 1)) {
                RecordSink sink = RecordSinkFactory.getInstance(asm, reader.getMetadata(), listColumnFilter, false);
                // this random will be populating values
                Rnd rnd2 = new Rnd();
                RecordCursor cursor = reader.getCursor();
                final Record record = cursor.getRecord();
                long counter = 0;
                while (cursor.hasNext()) {
                    MapKey key = map.withKey();
                    key.put(record, sink);
                    MapValue value = key.createValue();
                    Assert.assertTrue(value.isNew());
                    value.putFloat(4, rnd2.nextFloat());
                    value.putDouble(5, rnd2.nextDouble());
                    value.putDate(6, rnd2.nextLong());
                    value.putTimestamp(7, rnd2.nextLong());
                    value.putBool(8, rnd2.nextBoolean());
                    value.putLong(0, ++counter);
                    value.putInt(1, rnd2.nextInt());
                    value.putShort(2, rnd2.nextShort());
                    value.putByte(3, rnd2.nextByte());
                }
                cursor.toTop();
                rnd2.reset();
                long c = 0;
                while (cursor.hasNext()) {
                    MapKey key = map.withKey();
                    key.put(record, sink);
                    MapValue value = key.findValue();
                    Assert.assertNotNull(value);
                    Assert.assertEquals(rnd2.nextFloat(), value.getFloat(4), 0.000001f);
                    Assert.assertEquals(rnd2.nextDouble(), value.getDouble(5), 0.000000001);
                    Assert.assertEquals(rnd2.nextLong(), value.getDate(6));
                    Assert.assertEquals(rnd2.nextLong(), value.getTimestamp(7));
                    Assert.assertEquals(rnd2.nextBoolean(), value.getBool(8));
                    Assert.assertEquals(++c, value.getLong(0));
                    Assert.assertEquals(rnd2.nextInt(), value.getInt(1));
                    Assert.assertEquals(rnd2.nextShort(), value.getShort(2));
                    Assert.assertEquals(rnd2.nextByte(), value.getByte(3));
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 93 with RecordCursor

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

the class FastMapTest method testRowIdAccess.

@Test
public void testRowIdAccess() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        ColumnTypes types = new SingleColumnType(ColumnType.INT);
        final int N = 10000;
        final Rnd rnd = new Rnd();
        try (FastMap map = new FastMap(Numbers.SIZE_1MB, types, types, 64, 0.5, 1)) {
            for (int i = 0; i < N; i++) {
                MapKey key = map.withKey();
                key.putInt(rnd.nextInt());
                MapValue values = key.createValue();
                Assert.assertTrue(values.isNew());
                values.putInt(0, i + 1);
            }
            // reset random generator and iterate map to double the value
            rnd.reset();
            LongList list = new LongList();
            try (RecordCursor cursor = map.getCursor()) {
                final MapRecord record = (MapRecord) cursor.getRecord();
                while (cursor.hasNext()) {
                    list.add(record.getRowId());
                    Assert.assertEquals(rnd.nextInt(), record.getInt(1));
                    MapValue value = record.getValue();
                    value.putInt(0, value.getInt(0) * 2);
                }
                MapRecord rec = (MapRecord) cursor.getRecordB();
                Assert.assertNotSame(rec, record);
                rnd.reset();
                for (int i = 0, n = list.size(); i < n; i++) {
                    cursor.recordAt(rec, list.getQuick(i));
                    Assert.assertEquals((i + 1) * 2, rec.getInt(0));
                    Assert.assertEquals(rnd.nextInt(), rec.getInt(1));
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Test(org.junit.Test)

Example 94 with RecordCursor

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

the class FastMapTest method testGeohashRecordAsKey.

@Test
public void testGeohashRecordAsKey() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 5000;
        final Rnd rnd = new Rnd();
        int precisionBits = 10;
        int geohashType = ColumnType.getGeoHashTypeWithBits(precisionBits);
        BytecodeAssembler asm = new BytecodeAssembler();
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE)) {
            model.col("a", ColumnType.LONG).col("b", geohashType);
            CairoTestUtils.create(model);
        }
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < N; i++) {
                TableWriter.Row row = writer.newRow();
                long rndGeohash = GeoHashes.fromCoordinatesDeg(rnd.nextDouble() * 180 - 90, rnd.nextDouble() * 360 - 180, precisionBits);
                row.putLong(0, i);
                row.putGeoHash(1, rndGeohash);
                row.append();
            }
            writer.commit();
        }
        try (TableReader reader = new TableReader(configuration, "x")) {
            EntityColumnFilter entityColumnFilter = new EntityColumnFilter();
            entityColumnFilter.of(reader.getMetadata().getColumnCount());
            try (FastMap map = new FastMap(Numbers.SIZE_1MB, new SymbolAsStrTypes(reader.getMetadata()), new ArrayColumnTypes().add(ColumnType.LONG).add(ColumnType.INT).add(ColumnType.SHORT).add(ColumnType.BYTE).add(ColumnType.FLOAT).add(ColumnType.DOUBLE).add(ColumnType.DATE).add(ColumnType.TIMESTAMP).add(ColumnType.BOOLEAN), N, 0.9f, 1)) {
                RecordSink sink = RecordSinkFactory.getInstance(asm, reader.getMetadata(), entityColumnFilter, true);
                // this random will be populating values
                Rnd rnd2 = new Rnd();
                RecordCursor cursor = reader.getCursor();
                populateMap(map, rnd2, cursor, sink);
                try (RecordCursor mapCursor = map.getCursor()) {
                    long c = 0;
                    rnd.reset();
                    rnd2.reset();
                    final Record record = mapCursor.getRecord();
                    while (mapCursor.hasNext()) {
                        // value
                        Assert.assertEquals(++c, record.getLong(0));
                        Assert.assertEquals(rnd2.nextInt(), record.getInt(1));
                        Assert.assertEquals(rnd2.nextShort(), record.getShort(2));
                        Assert.assertEquals(rnd2.nextByte(), record.getByte(3));
                        Assert.assertEquals(rnd2.nextFloat(), record.getFloat(4), 0.000001f);
                        Assert.assertEquals(rnd2.nextDouble(), record.getDouble(5), 0.000000001);
                        Assert.assertEquals(rnd2.nextLong(), record.getDate(6));
                        Assert.assertEquals(rnd2.nextLong(), record.getTimestamp(7));
                        Assert.assertEquals(rnd2.nextBoolean(), record.getBool(8));
                    }
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 95 with RecordCursor

use of io.questdb.cairo.sql.RecordCursor 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

RecordCursor (io.questdb.cairo.sql.RecordCursor)174 Test (org.junit.Test)137 Record (io.questdb.cairo.sql.Record)123 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)108 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)87 TableWriter (io.questdb.cairo.TableWriter)71 Rnd (io.questdb.std.Rnd)29 LPSZ (io.questdb.std.str.LPSZ)10 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)7 SqlCompiler (io.questdb.griffin.SqlCompiler)6 DateFormat (io.questdb.std.datetime.DateFormat)6 Path (io.questdb.std.str.Path)6 StringSink (io.questdb.std.str.StringSink)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 SqlException (io.questdb.griffin.SqlException)4 BaseConnection (org.postgresql.core.BaseConnection)4 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)3 Instant (de.invesdwin.util.time.Instant)3