use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReaderMetadataTest method assertThat.
private void assertThat(String expected, ColumnManipulator manipulator, int columnCount) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(root).concat("all")) {
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
try (TableWriter writer = new TableWriter(configuration, "all")) {
manipulator.restructure(writer);
}
long pTranstionIndex = metadata.createTransitionIndex();
StringSink sink = new StringSink();
try {
metadata.applyTransitionIndex(pTranstionIndex);
Assert.assertEquals(columnCount, metadata.getColumnCount());
for (int i = 0; i < columnCount; i++) {
RecordColumnMetadata m = metadata.getColumnQuick(i);
sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
}
TestUtils.assertEquals(expected, sink);
if (expected.length() > 0) {
String[] lines = expected.split("\n");
Assert.assertEquals(columnCount, lines.length);
for (int i = 0; i < columnCount; i++) {
int p = lines[i].indexOf(':');
Assert.assertEquals(i, metadata.getColumnIndexQuiet(lines[i].substring(0, p)));
}
}
} finally {
TableReaderMetadata.freeTransitionIndex(pTranstionIndex);
}
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReaderMetadataTest method testColumnIndex.
@Test
public void testColumnIndex() {
ObjIntHashMap<String> expected = new ObjIntHashMap<>();
expected.put("int", 0);
expected.put("byte", 2);
expected.put("bin", 9);
expected.put("short", 1);
expected.put("float", 4);
expected.put("long", 5);
expected.put("xyz", -1);
expected.put("str", 6);
expected.put("double", 3);
expected.put("sym", 7);
expected.put("bool", 8);
expected.put("all.int", 0);
expected.put("all.byte", 2);
expected.put("all.bin", 9);
expected.put("all.short", 1);
expected.put("all.float", 4);
expected.put("all.long", 5);
expected.put("all.xyz", -1);
expected.put("all.str", 6);
expected.put("all.double", 3);
expected.put("all.sym", 7);
expected.put("zall.sym", -1);
try (Path path = new Path().of(root).concat("all").concat(TableUtils.META_FILE_NAME).$();
TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path)) {
for (ObjIntHashMap.Entry<String> e : expected) {
Assert.assertEquals(e.value, metadata.getColumnIndexQuiet(e.key));
}
}
}
use of com.questdb.std.str.Path 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, "all", 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++) {
RecordColumnMetadata m = metadata.getColumnQuick(i);
sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
}
TestUtils.assertEquals(expected, sink);
Assert.assertEquals(-1, metadata.getTimestampIndex());
} finally {
TableReaderMetadata.freeTransitionIndex(pTransitionIndex);
}
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableReaderMetadataTimestampTest method assertThatTimestampRemains.
private void assertThatTimestampRemains(TableReaderMetadataTest.ColumnManipulator manipulator, String expected, int expectedInitialTimestampIndex, int expectedFinalTimestampIndex, int expectedColumnCount) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (Path path = new Path().of(root).concat("all")) {
try (TableReaderMetadata metadata = new TableReaderMetadata(FilesFacadeImpl.INSTANCE, "all", path.concat(TableUtils.META_FILE_NAME).$())) {
Assert.assertEquals(12, metadata.getColumnCount());
Assert.assertEquals(expectedInitialTimestampIndex, metadata.getTimestampIndex());
try (TableWriter writer = new TableWriter(configuration, "all")) {
manipulator.restructure(writer);
}
long address = metadata.createTransitionIndex();
StringSink sink = new StringSink();
try {
metadata.applyTransitionIndex(address);
Assert.assertEquals(expectedColumnCount, metadata.getColumnCount());
for (int i = 0; i < expectedColumnCount; i++) {
RecordColumnMetadata m = metadata.getColumnQuick(i);
sink.put(m.getName()).put(':').put(ColumnType.nameOf(m.getType())).put('\n');
}
TestUtils.assertEquals(expected, sink);
Assert.assertEquals(expectedFinalTimestampIndex, metadata.getTimestampIndex());
} finally {
TableReaderMetadata.freeTransitionIndex(address);
}
}
}
});
}
use of com.questdb.std.str.Path in project questdb by bluestreak01.
the class TableUtilsTest method testCreate.
@Test
public void testCreate() {
final CharSequence root = temp.getRoot().getAbsolutePath();
final JournalMetadata metadata = getJournalStructure().build();
try (AppendMemory appendMemory = new AppendMemory()) {
try (Path path = new Path()) {
TableUtils.create(FF, path, appendMemory, root, metadata, 509);
Assert.assertEquals(TABLE_EXISTS, TableUtils.exists(FF, path, root, metadata.getName()));
path.of(root).concat(metadata.getName()).concat("_meta").$();
try (ReadOnlyMemory mem = new ReadOnlyMemory(FF, path, Files.PAGE_SIZE, FF.length(path))) {
long p = 0;
Assert.assertEquals(metadata.getColumnCount(), mem.getInt(p));
p += 4;
Assert.assertEquals(PartitionBy.NONE, mem.getInt(p));
p += 4;
Assert.assertEquals(metadata.getTimestampIndex(), mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.INT, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.DOUBLE, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.FLOAT, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.BYTE, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.LONG, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.STRING, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.BOOLEAN, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.SYMBOL, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.SHORT, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.DATE, mem.getInt(p));
p += 4;
Assert.assertEquals(ColumnType.DATE, mem.getInt(p));
p += 4;
p = assertCol(mem, p, "i");
p = assertCol(mem, p, "d");
p = assertCol(mem, p, "f");
p = assertCol(mem, p, "b");
p = assertCol(mem, p, "l");
p = assertCol(mem, p, "str");
p = assertCol(mem, p, "boo");
p = assertCol(mem, p, "sym");
p = assertCol(mem, p, "sho");
p = assertCol(mem, p, "date");
assertCol(mem, p, "timestamp");
}
}
}
}
Aggregations