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);
}
});
}
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);
}
}
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);
});
}
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;
}
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);
});
}
Aggregations