Search in sources :

Example 6 with Record

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

the class TableReaderTest method testOver2GFile.

@Test
public void testOver2GFile() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE).col("a", ColumnType.LONG)) {
            CairoTestUtils.create(model);
        }
        long N = 280000000;
        Rnd rnd = new Rnd();
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < N; i++) {
                TableWriter.Row r = writer.newRow();
                r.putLong(0, rnd.nextLong());
                r.append();
            }
            writer.commit();
        }
        try (TableReader reader = new TableReader(configuration, "x")) {
            int count = 0;
            rnd.reset();
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            while (cursor.hasNext()) {
                Assert.assertEquals(rnd.nextLong(), record.getLong(0));
                count++;
            }
            Assert.assertEquals(N, count);
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 7 with Record

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

the class TableReaderTest method testReadLong256Four.

@Test
public void testReadLong256Four() {
    try (TableModel model = new TableModel(configuration, "w", PartitionBy.DAY).col("l", ColumnType.LONG256).timestamp()) {
        CairoTestUtils.create(model);
    }
    final int N = 1_000_000;
    final Rnd rnd = new Rnd();
    long timestamp = 0;
    try (TableWriter writer = new TableWriter(configuration, "w")) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow(timestamp);
            row.putLong256(0, "0x" + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()));
            row.append();
        }
        writer.commit();
    }
    rnd.reset();
    final StringSink sink = new StringSink();
    try (TableReader reader = new TableReader(configuration, "w")) {
        final RecordCursor cursor = reader.getCursor();
        final Record record = cursor.getRecord();
        int count = 0;
        while (cursor.hasNext()) {
            sink.clear();
            record.getLong256(0, sink);
            TestUtils.assertEquals("0x" + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()) + padHexLong(rnd.nextLong()), sink);
            count++;
        }
        Assert.assertEquals(N, count);
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) StringSink(io.questdb.std.str.StringSink) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 8 with Record

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

the class TableReaderTest method testRemovePartition.

private void testRemovePartition(int partitionBy, CharSequence partitionNameToDelete, int affectedBand, NextPartitionTimestampProvider provider) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 100;
        int N_PARTITIONS = 5;
        long timestampUs = TimestampFormatUtils.parseTimestamp("2017-12-11T10:00:00.000Z");
        long stride = 100;
        int bandStride = 1000;
        int totalCount = 0;
        // model table
        try (TableModel model = new TableModel(configuration, "w", partitionBy).col("l", ColumnType.LONG).timestamp()) {
            CairoTestUtils.create(model);
        }
        try (TableWriter writer = new TableWriter(configuration, "w")) {
            for (int k = 0; k < N_PARTITIONS; k++) {
                long band = k * bandStride;
                for (int i = 0; i < N; i++) {
                    TableWriter.Row row = writer.newRow(timestampUs);
                    row.putLong(0, band + i);
                    row.append();
                    writer.commit();
                    timestampUs += stride;
                }
                timestampUs = provider.getNext(timestampUs);
            }
            Assert.assertEquals(N * N_PARTITIONS, writer.size());
            DateFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
            assert fmt != null;
            final long timestamp = fmt.parse(partitionNameToDelete, null);
            Assert.assertTrue(writer.removePartition(timestamp));
            Assert.assertFalse(writer.removePartition(timestamp));
            Assert.assertEquals(N * (N_PARTITIONS - 1), writer.size());
        }
        // now open table reader having partition gap
        try (TableReader reader = new TableReader(configuration, "w")) {
            Assert.assertEquals(N * (N_PARTITIONS - 1), reader.size());
            int previousBand = -1;
            int bandCount = 0;
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            while (cursor.hasNext()) {
                long value = record.getLong(0);
                int band = (int) ((value / bandStride) * bandStride);
                if (band != previousBand) {
                    // make sure we don#t pick up deleted partition
                    Assert.assertNotEquals(affectedBand, band);
                    if (previousBand != -1) {
                        Assert.assertEquals(N, bandCount);
                    }
                    previousBand = band;
                    bandCount = 0;
                }
                bandCount++;
                totalCount++;
            }
            Assert.assertEquals(N, bandCount);
        }
        Assert.assertEquals(N * (N_PARTITIONS - 1), totalCount);
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) DateFormat(io.questdb.std.datetime.DateFormat) Record(io.questdb.cairo.sql.Record)

Example 9 with Record

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

the class TableReaderTest method assertPartialCursor.

private long assertPartialCursor(RecordCursor cursor, Rnd rnd, long ts, long increment, long blob, long expectedSize, RecordAssert asserter) {
    int count = 0;
    Record record = cursor.getRecord();
    while (count < expectedSize && cursor.hasNext()) {
        count++;
        asserter.assertRecord(record, rnd, ts += increment, blob);
    }
    // did our loop run?
    Assert.assertEquals(expectedSize, count);
    return ts;
}
Also used : Record(io.questdb.cairo.sql.Record)

Example 10 with Record

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

the class TableReaderTest method testRemovePartitionReload.

private void testRemovePartitionReload(int partitionBy, CharSequence partitionNameToDelete, int affectedBand, NextPartitionTimestampProvider provider) throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 100;
        int N_PARTITIONS = 5;
        long timestampUs = TimestampFormatUtils.parseTimestamp("2017-12-11T00:00:00.000Z");
        long stride = 100;
        int bandStride = 1000;
        int totalCount = 0;
        // model table
        try (TableModel model = new TableModel(configuration, "w", partitionBy).col("l", ColumnType.LONG).timestamp()) {
            CairoTestUtils.create(model);
        }
        try (TableWriter writer = new TableWriter(configuration, "w")) {
            for (int k = 0; k < N_PARTITIONS; k++) {
                long band = k * bandStride;
                for (int i = 0; i < N; i++) {
                    TableWriter.Row row = writer.newRow(timestampUs);
                    row.putLong(0, band + i);
                    row.append();
                    writer.commit();
                    timestampUs += stride;
                }
                timestampUs = provider.getNext(timestampUs);
            }
            Assert.assertEquals(N * N_PARTITIONS, writer.size());
            // now open table reader having partition gap
            try (TableReader reader = new TableReader(configuration, "w")) {
                Assert.assertEquals(N * N_PARTITIONS, reader.size());
                RecordCursor cursor = reader.getCursor();
                Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    record.getLong(0);
                    totalCount++;
                }
                Assert.assertEquals(N * N_PARTITIONS, totalCount);
                DateFormat fmt = TableWriter.selectPartitionDirFmt(partitionBy);
                assert fmt != null;
                Assert.assertTrue(writer.removePartition(fmt.parse(partitionNameToDelete, null)));
                Assert.assertEquals(N * (N_PARTITIONS - 1), writer.size());
                reader.reload();
                totalCount = 0;
                Assert.assertEquals(N * (N_PARTITIONS - 1), reader.size());
                int previousBand = -1;
                int bandCount = 0;
                cursor = reader.getCursor();
                record = cursor.getRecord();
                while (cursor.hasNext()) {
                    long value = record.getLong(0);
                    int band = (int) ((value / bandStride) * bandStride);
                    if (band != previousBand) {
                        // make sure we don#t pick up deleted partition
                        Assert.assertNotEquals(affectedBand, band);
                        if (previousBand != -1) {
                            Assert.assertEquals(N, bandCount);
                        }
                        previousBand = band;
                        bandCount = 0;
                    }
                    bandCount++;
                    totalCount++;
                }
                Assert.assertEquals(N, bandCount);
            }
        }
        Assert.assertEquals(N * (N_PARTITIONS - 1), totalCount);
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) DateFormat(io.questdb.std.datetime.DateFormat) Record(io.questdb.cairo.sql.Record)

Aggregations

Record (io.questdb.cairo.sql.Record)171 Test (org.junit.Test)130 RecordCursor (io.questdb.cairo.sql.RecordCursor)121 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)79 TableWriter (io.questdb.cairo.TableWriter)70 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)66 Rnd (io.questdb.std.Rnd)32 Function (io.questdb.cairo.sql.Function)28 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)16 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)15 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)15 IntList (io.questdb.std.IntList)15 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)14 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)14 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)14 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)14 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)14 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)14 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)13 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)13