Search in sources :

Example 11 with RecordCursor

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

the class TableReaderTest method assertBatch2.

private void assertBatch2(int count, long increment, long ts, long blob, TableReader reader) {
    RecordCursor cursor = reader.getCursor();
    Rnd exp = new Rnd();
    long ts2 = assertPartialCursor(cursor, exp, ts, increment, blob, 3L * count, (r, rnd13, ts13, blob13) -> {
        BATCH1_ASSERTER.assertRecord(r, rnd13, ts13, blob13);
        BATCH2_BEFORE_ASSERTER.assertRecord(r, rnd13, ts13, blob13);
    });
    assertPartialCursor(cursor, exp, ts2, increment, blob, count, BATCH2_ASSERTER);
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor)

Example 12 with RecordCursor

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

the class TableReaderTest method testUnsuccessfulFileRemoveAndReloadStr.

@Test
public void testUnsuccessfulFileRemoveAndReloadStr() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        // create table with two string columns
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE).col("a", ColumnType.SYMBOL).col("b", ColumnType.STRING)) {
            CairoTestUtils.create(model);
        }
        Rnd rnd = new Rnd();
        final int N = 1000;
        // make sure we forbid deleting column "b" files
        TestFilesFacade ff = new TestFilesFacade() {

            int counter = 2;

            @Override
            public boolean remove(LPSZ name) {
                if (counter > 0 && ((Chars.endsWith(name, "b.i") || Chars.endsWith(name, "b.d") || Chars.endsWith(name, "b.o") || Chars.endsWith(name, "b.k") || Chars.endsWith(name, "b.c") || Chars.endsWith(name, "b.v")))) {
                    counter--;
                    return false;
                }
                return super.remove(name);
            }

            @Override
            public boolean wasCalled() {
                return counter < 1;
            }
        };
        CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }
        };
        // populate table and delete column
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < N; i++) {
                TableWriter.Row row = writer.newRow();
                row.putSym(0, rnd.nextChars(10));
                row.putStr(1, rnd.nextChars(15));
                row.append();
            }
            writer.commit();
            try (TableReader reader = new TableReader(configuration, "x")) {
                long counter = 0;
                rnd.reset();
                RecordCursor cursor = reader.getCursor();
                final Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    Assert.assertEquals(rnd.nextChars(10), record.getSym(0));
                    Assert.assertEquals(rnd.nextChars(15), record.getStr(1));
                    counter++;
                }
                Assert.assertEquals(N, counter);
                // this should write metadata without column "b" but will ignore
                // file delete failures
                writer.removeColumn("b");
                if (configuration.getFilesFacade().isRestrictedFileSystem()) {
                    reader.closeColumnForRemove("b");
                }
                // now when we add new column by same name it must not pick up files we failed to delete previously
                writer.addColumn("b", ColumnType.STRING);
                for (int i = 0; i < N; i++) {
                    TableWriter.Row row = writer.newRow();
                    row.putSym(0, rnd.nextChars(10));
                    row.putStr(1, rnd.nextChars(15));
                    row.append();
                }
                writer.commit();
                // now assert what reader sees
                Assert.assertTrue(reader.reload());
                Assert.assertEquals(N * 2, reader.size());
                rnd.reset();
                cursor.toTop();
                counter = 0;
                while (cursor.hasNext()) {
                    Assert.assertEquals(rnd.nextChars(10), record.getSym(0));
                    if (counter < N) {
                        // roll random generator to make sure it returns same values
                        rnd.nextChars(15);
                        Assert.assertNull(record.getStr(1));
                    } else {
                        Assert.assertEquals(rnd.nextChars(15), record.getStr(1));
                    }
                    counter++;
                }
                Assert.assertEquals(N * 2, counter);
            }
        }
        Assert.assertTrue(ff.wasCalled());
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) LPSZ(io.questdb.std.str.LPSZ) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 13 with RecordCursor

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

the class TableWriterTest method testO3AferRowCancel.

@Test
public void testO3AferRowCancel() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (TableModel model = new TableModel(configuration, "weather", PartitionBy.DAY).col("windspeed", ColumnType.DOUBLE).timestamp()) {
            CairoTestUtils.create(model);
        }
        try (TableWriter writer = new TableWriter(configuration, "weather")) {
            TableWriter.Row r;
            r = writer.newRow(IntervalUtils.parseFloorPartialDate("2021-01-31"));
            r.putDouble(0, 1.0);
            r.append();
            // Out of order
            r = writer.newRow(IntervalUtils.parseFloorPartialDate("2021-01-30"));
            r.putDouble(0, 1.0);
            r.cancel();
            // Back in order
            r = writer.newRow(IntervalUtils.parseFloorPartialDate("2021-02-01"));
            r.putDouble(0, 1.0);
            r.append();
            Assert.assertEquals(2, writer.size());
            writer.commit();
        }
        long[] expectedTs = new long[] { IntervalUtils.parseFloorPartialDate("2021-01-31"), IntervalUtils.parseFloorPartialDate("2021-02-01") };
        try (TableReader reader = new TableReader(configuration, "weather")) {
            int col = reader.getMetadata().getColumnIndex("timestamp");
            RecordCursor cursor = reader.getCursor();
            final Record r = cursor.getRecord();
            int i = 0;
            while (cursor.hasNext()) {
                Assert.assertEquals("Row " + i, expectedTs[i++], r.getTimestamp(col));
            }
            Assert.assertEquals(expectedTs.length, i);
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 14 with RecordCursor

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

the class CompactMapTest method testValueAccess.

@Test
public void testValueAccess() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 1000;
        final Rnd rnd = new Rnd();
        TestRecord.ArrayBinarySequence binarySequence = new TestRecord.ArrayBinarySequence();
        CairoTestUtils.createTestTable(N, rnd, binarySequence);
        BytecodeAssembler asm = new BytecodeAssembler();
        try (TableReader reader = new TableReader(configuration, "x")) {
            EntityColumnFilter entityColumnFilter = new EntityColumnFilter();
            entityColumnFilter.of(reader.getMetadata().getColumnCount());
            try (CompactMap map = new CompactMap(1024 * 1024, 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).add(ColumnType.getGeoHashTypeWithBits(5)).add(ColumnType.getGeoHashTypeWithBits(10)).add(ColumnType.getGeoHashTypeWithBits(20)).add(ColumnType.getGeoHashTypeWithBits(40)), N, 0.9, 1, Integer.MAX_VALUE)) {
                RecordSink sink = RecordSinkFactory.getInstance(asm, reader.getMetadata(), entityColumnFilter, true);
                // this random will be populating values
                Rnd rnd2 = new Rnd();
                RecordCursor cursor = reader.getCursor();
                final Record record = cursor.getRecord();
                populateMapGeo(map, rnd2, cursor, sink);
                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(++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));
                    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((byte) Math.abs(rnd2.nextByte()), value.getGeoByte(9));
                    Assert.assertEquals((short) Math.abs(rnd2.nextShort()), value.getGeoShort(10));
                    Assert.assertEquals(Math.abs(rnd2.nextInt()), value.getGeoInt(11));
                    Assert.assertEquals(Math.abs(rnd2.nextLong()), value.getGeoLong(12));
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 15 with RecordCursor

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

the class FastMapTest method testAllTypes.

@Test
public void testAllTypes() {
    Rnd rnd = new Rnd();
    ArrayColumnTypes keyTypes = new ArrayColumnTypes();
    ArrayColumnTypes valueTypes = new ArrayColumnTypes();
    keyTypes.add(ColumnType.BYTE);
    keyTypes.add(ColumnType.SHORT);
    keyTypes.add(ColumnType.INT);
    keyTypes.add(ColumnType.LONG);
    keyTypes.add(ColumnType.FLOAT);
    keyTypes.add(ColumnType.DOUBLE);
    keyTypes.add(ColumnType.STRING);
    keyTypes.add(ColumnType.BOOLEAN);
    keyTypes.add(ColumnType.DATE);
    keyTypes.add(ColumnType.getGeoHashTypeWithBits(3));
    valueTypes.add(ColumnType.BYTE);
    valueTypes.add(ColumnType.SHORT);
    valueTypes.add(ColumnType.INT);
    valueTypes.add(ColumnType.LONG);
    valueTypes.add(ColumnType.FLOAT);
    valueTypes.add(ColumnType.DOUBLE);
    valueTypes.add(ColumnType.BOOLEAN);
    valueTypes.add(ColumnType.DATE);
    valueTypes.add(ColumnType.getGeoHashTypeWithBits(20));
    try (FastMap map = new FastMap(64, keyTypes, valueTypes, 64, 0.8, 24)) {
        final int N = 100000;
        for (int i = 0; i < N; i++) {
            MapKey key = map.withKey();
            key.putByte(rnd.nextByte());
            key.putShort(rnd.nextShort());
            key.putInt(rnd.nextInt());
            key.putLong(rnd.nextLong());
            key.putFloat(rnd.nextFloat());
            key.putDouble(rnd.nextDouble());
            if ((rnd.nextPositiveInt() % 4) == 0) {
                key.putStr(null);
            } else {
                key.putStr(rnd.nextChars(rnd.nextPositiveInt() % 16));
            }
            key.putBool(rnd.nextBoolean());
            key.putDate(rnd.nextLong());
            key.putShort(rnd.nextShort());
            MapValue value = key.createValue();
            Assert.assertTrue(value.isNew());
            value.putByte(0, rnd.nextByte());
            value.putShort(1, rnd.nextShort());
            value.putInt(2, rnd.nextInt());
            value.putLong(3, rnd.nextLong());
            value.putFloat(4, rnd.nextFloat());
            value.putDouble(5, rnd.nextDouble());
            value.putBool(6, rnd.nextBoolean());
            value.putDate(7, rnd.nextLong());
            value.putInt(8, rnd.nextInt());
        }
        rnd.reset();
        // assert that all values are good
        for (int i = 0; i < N; i++) {
            MapKey key = map.withKey();
            key.putByte(rnd.nextByte());
            key.putShort(rnd.nextShort());
            key.putInt(rnd.nextInt());
            key.putLong(rnd.nextLong());
            key.putFloat(rnd.nextFloat());
            key.putDouble(rnd.nextDouble());
            if ((rnd.nextPositiveInt() % 4) == 0) {
                key.putStr(null);
            } else {
                key.putStr(rnd.nextChars(rnd.nextPositiveInt() % 16));
            }
            key.putBool(rnd.nextBoolean());
            key.putDate(rnd.nextLong());
            key.putShort(rnd.nextShort());
            MapValue value = key.createValue();
            Assert.assertFalse(value.isNew());
            Assert.assertEquals(rnd.nextByte(), value.getByte(0));
            Assert.assertEquals(rnd.nextShort(), value.getShort(1));
            Assert.assertEquals(rnd.nextInt(), value.getInt(2));
            Assert.assertEquals(rnd.nextLong(), value.getLong(3));
            Assert.assertEquals(rnd.nextFloat(), value.getFloat(4), 0.000000001f);
            Assert.assertEquals(rnd.nextDouble(), value.getDouble(5), 0.000000001d);
            Assert.assertEquals(rnd.nextBoolean(), value.getBool(6));
            Assert.assertEquals(rnd.nextLong(), value.getDate(7));
            Assert.assertEquals(rnd.nextInt(), value.getInt(8));
        }
        try (RecordCursor cursor = map.getCursor()) {
            rnd.reset();
            assertCursor1(rnd, cursor);
            rnd.reset();
            cursor.toTop();
            assertCursor1(rnd, cursor);
        }
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) 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