use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class TableReaderMetadataTimestampTest method assertThat.
private void assertThat(String expected, int expectedInitialTimestampIndex) throws Exception {
int columnCount = 11;
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(root).concat("all")) {
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, path.concat(TableUtils.META_FILE_NAME).$())) {
Assert.assertEquals(12, metadata.getColumnCount());
Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
try (TableWriter writer = new TableWriter(configuration, "all")) {
writer.removeColumn("timestamp");
}
long pTransitionIndex = metadata.createTransitionIndex();
StringSink sink = new StringSink();
try {
metadata.applyTransitionIndex(pTransitionIndex);
Assert.assertEquals(columnCount, metadata.getColumnCount());
for (int i = 0; i < columnCount; i++) {
sink.put(metadata.getColumnName(i)).put(':').put(ColumnType.nameOf(metadata.getColumnType(i))).put('\n');
}
TestUtils.assertEquals(expected, sink);
Assert.assertEquals(-1, metadata.getTimestampIndex());
} finally {
TableUtils.freeTransitionIndex(pTransitionIndex);
}
}
}
});
}
use of io.questdb.std.str.StringSink 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.std.str.StringSink in project questdb by bluestreak01.
the class CompactMapTest method testUnableToFindFreeSlot2.
@Test
public void testUnableToFindFreeSlot2() {
// test that code that deals with key collection is always
// protected by map capacity check.
Rnd rnd = new Rnd();
// these have to be power of two for on the limit testing
// QMap will round capacity to next highest power of two!
int N = 256;
int M = 32;
StringSink sink = new StringSink();
// tweak capacity in such a way that we only have one spare slot before resize is needed
// this way algo that shuffles "foreign" slots away should face problems
double loadFactor = 0.9999999;
try (CompactMap map = new CompactMap(1024 * 1024, new SingleColumnType(ColumnType.STRING), new SingleColumnType(ColumnType.LONG), (long) (N * loadFactor), loadFactor, new MockHash(), 1, Integer.MAX_VALUE)) {
// assert that key capacity is what we expect, otherwise this test would be useless
Assert.assertEquals(N, map.getActualCapacity());
long target = map.getKeyCapacity();
sink.clear();
sink.put("000");
for (long i = 0; i < target - 2; i++) {
// keep the first character
sink.clear(3);
rnd.nextChars(sink, 5);
MapKey key = map.withKey();
key.putStr(sink);
MapValue value = key.createValue();
Assert.assertTrue(value.isNew());
value.putLong(0, i + 1);
}
sink.clear();
sink.put(target - 2);
populate(rnd, sink, map, target - 1, M + N, 3);
// assert result
rnd.reset();
sink.clear();
sink.put("000");
assertMap(rnd, sink, map, 0, target - 2, 3);
sink.clear();
sink.put(target - 2);
assertMap(rnd, sink, map, target - 1, M + N, 3);
}
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class CompactMapTest method testUnableToFindFreeSlot.
@Test
public void testUnableToFindFreeSlot() {
// test what happens when map runs out of free slots while trying to
// reshuffle "foreign" entries out of the way
Rnd rnd = new Rnd();
// these have to be power of two for on the limit testing
// QMap will round capacity to next highest power of two!
int N = 256;
int M = 32;
// string is always a number and this number will be hash code of string.
class MockHash implements CompactMap.HashFunction {
@Override
public long hash(MemoryR mem, long offset, long size) {
// we have single key field, which is string
// the offset of string is 8 bytes for key cell + 4 bytes for string length, total is 12
char c = mem.getChar(offset + 12);
return c - '0';
}
}
StringSink sink = new StringSink();
// tweak capacity in such a way that we only have one spare slot before resize is needed
// this way algo that shuffles "foreign" slots away should face problems
double loadFactor = 0.9999999;
try (CompactMap map = new CompactMap(1024 * 1024, new SingleColumnType(ColumnType.STRING), new SingleColumnType(ColumnType.LONG), (long) (N * loadFactor), loadFactor, new MockHash(), 1, Integer.MAX_VALUE)) {
// assert that key capacity is what we expect, otherwise this test would be useless
Assert.assertEquals(N, map.getActualCapacity());
testUnableToFindFreeSlot0(rnd, N, M, sink, map);
map.clear();
rnd.reset();
testUnableToFindFreeSlot0(rnd, N, M, sink, map);
}
}
use of io.questdb.std.str.StringSink in project questdb by bluestreak01.
the class FullFwdDataFrameCursorTest method assertMetadataEquals.
private void assertMetadataEquals(RecordMetadata a, RecordMetadata b) {
StringSink sinkA = new StringSink();
StringSink sinkB = new StringSink();
a.toJson(sinkA);
b.toJson(sinkB);
TestUtils.assertEquals(sinkA, sinkB);
}
Aggregations